jQuery触发器无法在IE中运行。 为什么?

$('#XynBp0').find('input').each(function(){ if ($(this).attr('value') == 'Cancel'){ $(this).trigger('click'); } }); 

在IE7中不起作用

这很奇怪,但尝试创建一个自定义事件

 $('#XynBp0 input').bind('custom',function(){ //code }) $('#XynBp0').find('input').each(function(){ if ($(this).attr('value') == 'Cancel'){ $(this).trigger('custom'); } }); 

这有用吗?

$.click() $.trigger('click') $.click() (或$.trigger('click') )不会模拟鼠标点击; 它会触发绑定到该元素的任何onclick事件。 如果您尚未为要搜索的输入分配onclick事件,则不会发生任何事情。

听起来你正试图用传统的提交按钮提交表单(例如 )。 如果是这种情况,您可能必须使用$(yourform).submit()来提交表单,并结合对发送到服务器的数据的一些处理来模拟单击“取消”按钮。

它是否包含在dom ready事件中? 如果您提供更多代码,可能会有所帮助。

 $(function () { $('#XynBp0').find('input').each(function () { if ($(this).attr('value') == 'Cancel') { $(this).trigger('click'); } }); }); 

您的代码snippit没有任何意义,如果取消它们,您点击输入?

这里有一些要清理的代码

 $('input','#XynBp0').each(function () { var $this = $(this); if ( this.value === 'Cancel' ) { //Don't need jQuery here $this.trigger('click'); //Probably don't need it here either } }); 

点击甚至做什么? 如果您要提交表单,请使用form.submit();