admin管理员组文章数量:1307136
I'm trying to find whether there is some character in my string in JS
Like that :
$('.upld_btn').bind("click", function () {
changeApiFormat($('#embbed').val());
});
if ($('#embbed.contains("?vid=")')) {
....
....
}
I've got an error in my google chrome console :
Object XXXX has no method 'contains'
How e?!
I'm trying to find whether there is some character in my string in JS
Like that :
$('.upld_btn').bind("click", function () {
changeApiFormat($('#embbed').val());
});
if ($('#embbed.contains("?vid=")')) {
....
....
}
I've got an error in my google chrome console :
Object XXXX has no method 'contains'
How e?!
Share Improve this question edited Sep 10, 2013 at 22:40 frydoubt 7711 bronze badges asked Sep 9, 2012 at 20:42 thormayerthormayer 1,0706 gold badges29 silver badges49 bronze badges3 Answers
Reset to default 6I assume #embbed
is an input value of some kind (because of your call to .val()
above). So, you would want to pull its value here, as well, and use indexOf
(-1
indicates not found):
if ($("#embbed").val().indexOf('?vid=') != -1) {
Here is a jsFiddle illustrating proof-of-concept. Enter "Hi", or "aHia", or anything like that (case-sensitive) into the box and click the link, and you will get a success popup. Otherwise you will get a failure popup.
Code used:
$(document).ready(function() {
$(".clicky").click(function() {
if ($("#input").val().indexOf('Hi') != -1) {
alert("Contains 'Hi'!");
} else {
alert("No luck!");
}
return false;
});
});
To use the contains() selector your syntax is not correct, assuming that is what you are trying to achieve:
if ($('#embbed:contains("?vid=")').length) {
....
}
See http://api.jquery./contains-selector/
It's :contains
instead of .contains
:
$('#embbed:contains("?vid=")')
本文标签: javascriptcontains is object has no methodStack Overflow
版权声明:本文标题:javascript - contains is object has no method? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741797911a2398046.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论