2

我有需要点击事件来启用数据表的 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 });

以上事件未触发。这里有什么问题?

4

3 回答 3

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()用于动态代码。

于 2013-06-13T00:39:25.267 回答
0

您无需使用 . 将事件处理程序附加到“搜索”按钮.click()。单击按钮时执行的功能是您在“按钮”选项中指定的功能。在您的情况下,单击“搜索”按钮时执行的功能是:

function() {
    jQuery.ajax({
        type: 'POST',
        url : '<s:url action="part" method="list" />'
    })
}

只需将该功能更改为您想要的功能即可。

于 2013-06-13T04:38:01.427 回答
0

此选择器jQuery("Search")正在搜索 的元素Search。如果Search是 ID,则需要使用 ID#选择器:

jQuery("#Search").click(function() { console.log("hello"); });

此外,在您的点击功能中,我不确定是什么Hello,但我想您想要一个警报或日志。

于 2013-06-13T00:37:10.343 回答