如何使用ASPNETMVCturbolinks在正文中编写jQuery

how to write jquery in body when using aspnetmvcturbolinks

本文关键字:jQuery 正文 何使用 ASPNETMVCturbolinks      更新时间:2023-09-26

我在自己的项目中使用 aspnetmvcturbolinks,但是,在 body 中编写的 jquery API 是未定义的。我将js文件移动到布局的头部。

$(document).on('keyup', 'input[name=keyword]', function () {
alert(this.attr("name"));
return false;
});

在上面的代码中,attr API 是无法找到的!! 什么是解决方案?谢谢。

这是因为你必须this传递给jQuery才能使用jQuery方法...

$(this).attr("name")

。否则,它会查看对象并返回未定义的

相关文章: