开发者

jQuery trigger not working in IE. Why?

开发者 https://www.devze.com 2023-01-20 12:52 出处:网络
$(\'#XynBp0\').find(\'input\').each(function(){ if ($(this).attr(\'value\') == \'Cancel\'){ $(this).trigger(\'click\'开发者_如何学运维);
$('#XynBp0').find('input').each(function(){
    if ($(this).attr('value') == 'Cancel'){
        $(this).trigger('click'开发者_如何学运维);
    }
});

doesn't work in IE7


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?


$.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.


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

});


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();

0

精彩评论

暂无评论...
验证码 换一张
取 消