在使用来自不同页面的不同 ID 时,我遇到了 DOMREADY 的问题。例如
JS
var clickFunction = function(){
//put whatever you want to happen in here
alert('this element now recognizes the click event');
}
window.addEvent('domready', function() {
$('id_name').addEvent('click', clickFunction);
});
window.addEvent('domready', function() {
$('id_2').addEvent('click', clickFunction);
});
HTML案例1
<body>
<div id="id_name"> <a onclick="javascript:void(0);">link1</a></div>
<div id="id_2"> <a onclick="javascript:void(0);">link2</a></div>
</body>
单击link2时它工作正常
案例2
<body>
<div id="id_name"> <a onclick="javascript:void(0);">link1</a> </div>
</body>
当点击link1时它工作正常
案例3
<body>
<div id="id_2"> <a onclick="javascript:void(0);">link2</a> </div>
</body>
它不起作用