我的 HTML:
<form>
<input type="text" name="url" maxlength="10" />
</form>
我的 JS:
$(document).ready(function(){
var inputUrl = $('input[name=url]');
inputUrl.change(function() {
alert(inputUrl);
if ($(inputUrl).contains('watch'))
{
alert ('Contains watch: yes');
}
else
{
alert ('Contains watch: no');
}
});
});
Chrome 控制台显示:
Uncaught TypeError: Object [object Object] has no method 'contains'
什么是正确的语法:
if ($(inputUrl).contains('watch'))