我有很多输入字段在按下回车键时发布数据我做了一件事我找到了所选按钮的 ID 并想通过点击事件 bt 它给出错误这里是代码
$(".text").bind("keydown", function(event) {
// track enter key
var keycode = (event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode));
if (keycode == 13) {
var id=$(this).parent().find("input[type=submit]").attr('id');
(id).click(); // this one give error
return false;
} else {
return true;
}
});
(id).click(); 此行给出错误,id.click 不是函数。我缺少什么。
最佳答案
我想你正在寻找:
$(this).closest("form").find("input[type=submit]").trigger("click");
无需尝试查找 id
并创建不同的 JQuery 对象。您将通过 find("input[type=submit]")
找到您要查找的内容的引用。
为了确定,我们需要查看您的标记,以便找到最有效的方法来查找您要查找的元素,
关于php - 如何为 .click 事件赋值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15116604/