有一個div經常由ajax改變它的innerHTML。一旦頁面加載,jQuery function()可以工作,但是當innerHTML由ajax改變時,某些功能不起作用。我使用螢火蟲檢查了代碼並嘗試簡單地解釋它。**jQuery fn()沒有加載/運行?
我認爲DOM只會在第一次加載頁面時加載js文件,並且如果ajax修改了innerHTML,那麼函數不會以某種方式調用。您說什麼?根據你的解決方案是什麼? HTML頁面
<body>
<div class="_div_change"> dynamically class add by jQuery function()
here contenet is added by ajax functionality
</div>
<script type="text/javascript">
$(function(){
$('._div_change').addClass('.div_class');
});
</script>
</body>
Loading first time & class is added by fn() |only div innerHTML modified by ajax ***
|
<div class="_div_change div_class"> | <div class="_div_change">
innerHTML elements added successfully| innerHTML elements altered successfully
</div> | </div>
感謝TJ描述邏輯。編輯腳本。 – Bibhaw 2011-04-29 08:42:46