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);
}
相關文章
相關標籤/搜索