【发布时间】:2014-07-28 19:01:42
【问题描述】:
我引用了Creating a div element in jQuery 并使用 javascript 创建了一个 div 元素。但是,当我动态添加按钮元素时,单击不起作用。我们需要做哪些更改才能使按钮单击起作用?
注意:由于Binding to multiple view models nested in the Dom 中提到的剑道控制要求,我们不能将函数移到 document.ready 之外
更新的参考文献
- Wiring up click event using jQuery on() doesn't fire on injected HTML via Ajax call
- how to attach jquery event handlers for newly injected html?
- After injecting html by jquery, the event handlers doesn't work with/without delegate
代码
<head>
<title>Test</title>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://cdn.kendostatic.com/2013.2.716/js/kendo.all.min.js"></script>
<script type="text/javascript">
//lijo
$(document).ready(function ()
{
$(".statiscDIV").append('<div>FIRST</div>');
$(".statiscDIV").append('<div>hello <button class="MakeHoldDetailLinkButton" onclick = "showMakeAndHold();">View</button> </div>');
//lijo
function showMakeAndHold()
{
alert("HIIIIIII");
}
});
</script>
</head>
<body>
<div class="statiscDIV">
A
</div>
</body>
【问题讨论】:
标签: javascript jquery