PHP數(shù)組函數(shù)uksort()的用法
699
2024-01-03
代碼1: 以此方法綁定的input框事件,在通過add按鈕后用jquery綁定的事件 alert就會丟失
<input type="button" value="Add" name="test_but" /> <div id="test_div"><input name="test_input"/></div> <script> $('input[name=test_input]').change(function(){ alert($(this).val()) ; }); $('input[name=test_but]').click(function(){ $('input[name=test_input]').clone().appendTo($('#test_div')); }); </script>
代碼2: 以jquery的live方法綁定change事件,alert不會丟失,但是在點(diǎn)擊add時有可能多次添加input,或者多次彈出提醒框,刷新頁面后就好了,但是多次操作后還是會這樣
<input type="button" value="Add" name="test_but" /> <div id="test_div"><input name="test_input" onchange="alert_val(this)"/></div> <script> $('input[name=test_input]').live('change',function(){ alert($(this).val()) ; }); $('input[name=test_but]').click(function(){ $('input[name=test_input]').clone().appendTo($('#test_div')); }); </script>
代碼3: 解決之道....
<input type="button" value="Add" name="test_but" /> <div id="test_div"><input name="test_input" onchange="alert_val(this)"/></div> <script> function alert_val(obj){ alert($(obj).val()); } $('input[name=test_but]').click(function(){ $('input[name=test_input]').clone().appendTo($('#test_div')); }); </script>
通過js原生態(tài)的onchange事件,把對象本身傳遞進(jìn)去,這樣既可以用到j(luò)query語法繼續(xù)寫東西,也不會丟失綁定事件,更加不會因?yàn)閘ive的特性導(dǎo)致事件多次執(zhí)行....完美!
#免責(zé)聲明#
本站[綠夏技術(shù)導(dǎo)航]提供的一切軟件、教程和內(nèi)容信息僅限用于學(xué)習(xí)和研究目的;不得將上述內(nèi)容用于商業(yè)或者非法用途,否則,一切后果請用戶自負(fù)。本站信息來自網(wǎng)絡(luò)收集整理,版權(quán)爭議與本站無關(guān)。您必須在下載后的24個小時之內(nèi),從您的電腦或手機(jī)中徹底刪除上述內(nèi)容。如果您喜歡該程序或內(nèi)容,請支持正版,購買注冊,得到更好的正版服務(wù)。我們非常重視版權(quán)問題,如有侵權(quán)請郵件[admin@lxwl520.com]與我們聯(lián)系進(jìn)行刪除處理。敬請諒解!