Jquery使用trigger()方法模拟事件

1、模拟select
php

$('#selectCount').change(function(){
    $('select#some').val(10).change();
    //or
    $('select#some').val(10).trigger('change');
}


2、模拟点击ide

$("button:first").click(function () {
    update($("span:first"));
});
$("button:last").click(function () {
    $("button:first").trigger('click');
   update($("span:last"));
});
 
function update(j) {
    var n = parseInt(j.text(), 10);
    j.text(n + 1);
}
相关文章
相关标签/搜索