gar*_*ryM 4 javascript jquery triggers bind
我只想加快jQuery的速度,如果这是一个菜鸟错误,我会在前面道歉.
我试图让一个简单的自定义触发器在没有成功的情况下触发.也许有人可以帮忙,并告诉我为什么这不起作用.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>jQuery Trigger example</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
$('#asset1').bind("triggerAssets", function() {
alert('Assets');
});
</script>
<script>
$(document).ready(function(){
$('#asset1').trigger("triggerAssets");
});
</script>
</head>
<body >
<div id="asset1" class="assets" >Asset
<table>
<tr>
<td>Field One: </td>
<td><input type="text" name="fieldOne" id="exfieldOne" value=""/></td>
</tr>
<tr>
<td>Field Two: </td>
<td><input type="text" name="fieldTwo" id="exfieldTwo" value=""/></td>
</tr>
<tr>
<td>Field Three: </td>
<td><input type="text" name="fieldThree" id="exfieldThree" value=""/></td>
</tr>
</table>
</div>
<hr>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
您的绑定功能将在呈现页面之前运行; #asset1尚不存在.将其移动到ready处理程序中,该处理程序在DOM准备就绪后触发(并且您的元素存在).
$(document).ready(function(){ // wait until the DOM is ready, then do:
$('#asset1').bind("triggerAssets", function() {
alert('Assets');
});
$('#asset1').trigger("triggerAssets");
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2058 次 |
| 最近记录: |