1 javascript function typeerror
未捕获的类型错误:$(this).search 不是函数
$(document).ready(function(){
$('#caption').on('keypress', function () {
var n = $(this).search('#');
if(n != "-1"){
window.alert("There's a hash");
}else{
window.alert("There's not a hash");
}
});
});
Run Code Online (Sandbox Code Playgroud)
小智 5
search 是字符串类型的 JavaScript 方法。
因此,如果您想使用search,您的行var n = $(this).search('#');应该更改为var n = $(this).val().search('#');或var n = $(this).text().search('#');取决于#caption元素的标签。
| 归档时间: |
|
| 查看次数: |
9761 次 |
| 最近记录: |