jquery trigger實現(xiàn)聯(lián)動的方法
本文實例講述了jquery trigger實現(xiàn)聯(lián)動的方法。分享給大家供大家參考,具體如下:
<html> <head> <title>testing</title> <script src="jquery-1.3.2.min.js" type="text/javascript"></script> <script type="text/javascript"> $(function () { $("#Provinces").change(function (e,cityValue) { if ($(this).val() == "1") { $("#City").html("<option value='1' >長沙</option><option value='2' >衡陽</option>"); } else { $("#City").html("<option value='1' >武漢</option><option value='2' >襄陽</option>"); } if (typeof (cityValue) != "undefined") { $("#City").val(cityValue); } }); }); function test() { $("#Provinces").val("2"); $("#Provinces").trigger("change","2"); } </script> </head> <body> ?。? <select id="Provinces" > <option value="1" >湖南</option> <option value="2" >湖北</option> </select><br /> 市: <select id="City"> <option value="1" >長沙</option> <option value="2" >衡陽</option> </select><br /> <input type="button" value="設置成湖北襄陽" onclick="test()" /> </body> </html>
眾所周知, trigger 是異步的, 在其后面執(zhí)行的代碼可能會跑到它前面去執(zhí)行, 上面的代碼就避免了這一點。
更多關于jQuery相關內(nèi)容感興趣的讀者可查看本站專題:《jQuery拖拽特效與技巧總結》、《jQuery擴展技巧總結》、《jQuery常見經(jīng)典特效匯總》、《jQuery動畫與特效用法總結》、《jquery選擇器用法總結》及《jQuery常用插件及用法總結》
希望本文所述對大家jQuery程序設計有所幫助。
- jQuery中trigger()方法用法實例
- jquery trigger偽造a標簽的click事件取代window.open方法
- jQuery如何使用自動觸發(fā)事件trigger
- jquery的trigger和triggerHandler的區(qū)別示例介紹
- jquery中trigger()無法觸發(fā)hover事件的解決方法
- jquery trigger函數(shù)執(zhí)行兩次的解決方法
- jQuery trigger()方法用法介紹
- jQuery中trigger()與bind()用法分析
- jQuery中triggerHandler()方法用法實例
- jQuery中值得注意的trigger方法淺析
相關文章
jQuery插件zTree實現(xiàn)獲取當前選中節(jié)點在同級節(jié)點中序號的方法
這篇文章主要介紹了jQuery插件zTree實現(xiàn)獲取當前選中節(jié)點在同級節(jié)點中序號的方法,結合實例形式分析了屬性插件zTree針對節(jié)點序號的相關操作技巧,需要的朋友可以參考下2017-03-03jquery(live)中File input的change方法只起一次作用的解決辦法
jquery中File input的change方法只起一次作用的解決辦法,需要的朋友可以參考下。2011-10-10jQuery 函數(shù)實例分析【函數(shù)聲明、函數(shù)表達式、匿名函數(shù)等】
這篇文章主要介紹了jQuery 函數(shù),結合實例形式分析了jquery函數(shù)聲明、函數(shù)表達式、匿名函數(shù)等相關使用技巧,需要的朋友可以參考下2020-05-05