jQuery trigger not working in IE. Why?

送分小仙女□ 提交于 2019-12-10 20:27:36

问题


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

doesn't work in IE7


回答1:


it's strange but try to create a custom event

$('#XynBp0 input').bind('custom',function(){
 //code
})


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

Does this work?




回答2:


$.click() (or $.trigger('click')) doesn't simulate a mouse click; it fires off any onclick events bound to that element. If you haven't assigned an onclick event to that input you're searching for, nothing will happen.

It sounds like you're trying to submit the form with a traditional submit button (e.g. <input type="submit" value="Cancel">). If that's the case, you may have to use $(yourform).submit() to submit the form, in combination with some handling of the data sent to the server to simulate clicking the Cancel button.




回答3:


Is it wrapped in a dom ready event? Might help if you provide more code.

$(function () {

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

});



回答4:


Your code snippit doesn't make any sense, you are clicking inputs if they are canceled?

Here's some things to clean up in your code

$('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
  }
});

What does click even do? If you are trying to submit a form, use form.submit();



来源:https://stackoverflow.com/questions/3938215/jquery-trigger-not-working-in-ie-why

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!