$('#XynBp0').find('input').each(function(){
if ($(this).attr('value') == 'Cancel'){
$(this).trigger('click');
}
});
在IE7中无法正常工作
$('#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')
)并不模拟鼠标点击,它会触发绑定到该元素的任何onclick事件。如果您没有为要查找的输入分配onclick事件,则什么也不会发生。
听起来你正在尝试使用传统的提交按钮提交表单(例如<input type="submit" value="Cancel">
)。如果是这种情况,您可能需要使用$(yourform).submit()
提交表单,并处理发送到服务器的数据以模拟单击“取消”按钮。
它是否包含在DOM准备事件中?如果您提供更多代码可能会有所帮助。
$(function () {
$('#XynBp0').find('input').each(function () {
if ($(this).attr('value') == 'Cancel') {
$(this).trigger('click');
}
});
});
你的代码片段没有任何意义,你在点击已取消的输入框吗?
以下是需要清理的一些代码:
$('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
}
});
click 事件到底是做什么的?如果你想要提交表单,请使用 form.submit();
$(this).attr('value')
包含什么?还是触发器没有触发? - Pekka$("#XynBp0 input[value='Cancel']").trigger('click');
- mpen