<script>
$(".box").bind("update",function(txt){
alert(txt);
});
$(".box").trigger("update","Test text");
</script>
<div class="box" style="width:100px;">Nothing to say</div>
Run Code Online (Sandbox Code Playgroud)
我想:警告"测试文本".
我得到:警告"[对象]"
怎么了?
事件处理程序的第一个参数是事件对象,因此接受数据作为第二个参数
$(".box").bind("update", function(event, txt) {
alert(txt);
});
$(".box").trigger("update", "Test text");Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="box" style="width:100px;">Nothing to say</div>Run Code Online (Sandbox Code Playgroud)