我有jquery按钮,需要点击事件才能启用数据表。请查看下面的代码建议。
jQuery( "#dialog-form" ).dialog({
autoOpen: false,
height: 500,
width: 750,
modal: true,
buttons : {
"Search" : function() {
jQuery.ajax({type : 'POST',
url : ' <s:url action="part" method="list" /> '
})
}
}
});
现在我需要编写搜索按钮点击事件。
jQuery("Search").click(function() { Hello });
以上事件没有触发。这里有什么问题?
答案 0 :(得分:2)
应该是
//really concise and great if you're not passing parameters
jQuery("#Search").on('click', Hello);
或
// you had Hello instead of Hello();
jQuery("#Search").on('click', function() { Hello(); });
使用 .on() 获取动态代码。
答案 1 :(得分:0)
此选择器jQuery("Search")
正在搜索Search
的元素。如果Search
是ID,则需要使用ID #
选择器:
jQuery("#Search").click(function() { console.log("hello"); });
此外,在您的点击功能中,我不确定Hello
是什么,但我认为您需要提醒或日志。
答案 2 :(得分:0)
您无需使用.click()
将事件处理程序附加到“搜索”按钮。单击按钮时执行的功能是您在“按钮”选项中指定的功能。在您的情况下,单击“搜索”按钮时执行的功能是:
function() {
jQuery.ajax({
type: 'POST',
url : '<s:url action="part" method="list" />'
})
}
只需将该功能更改为您想要的功能即可。