有關多選與單選(轉載) 取得連結 Facebook X Pinterest 以電子郵件傳送 其他應用程式 7月 21, 2016 $(".grpCbx").click(function() { $(".grpCbx").not(this).removeAttr("checked"); }); 將其他check清空,使用專屬jquery的 .not(this) 來處理 原出處 http://blog.darkthread.net/post-2009-05-29-something-about-js-event.aspx 取得連結 Facebook X Pinterest 以電子郵件傳送 其他應用程式 留言
jQuery獲取Select選擇的Text和Value(轉) 7月 19, 2016 jQuery獲取Select選擇的Text和Value(轉) jQuery獲取Select選擇的Text和Value: 語法解釋: 1. $("#select_id").change(function(){//code...}); //為Select添加事件,當選擇其中一項時觸發 2. var checkText=$("#select_id").find("option:selected").text(); //獲取Select選擇的Text 3. var checkValue=$("#select_id").val() ; //獲取Select選擇的Value 4. var checkIndex=$("#select_id ").get(0).selectedIndex; //獲取Select選擇的索引值 5. var maxIndex=$("#select_id option:last" ).attr("index"); //獲取Select最大的索引值 jQuery設置Select選擇的Text和Value: 語法解釋: 1. $("#select_id ").get(0).selectedIndex=1; //設置Select索引值為1的項選中 2. $("#select_id ").val(4); //設置Select的Value值為4的項選中 3. $("#select_id option[text='jQuery' ]").attr("selected", true); //設置Select的Text值為jQuery的項選中 jQuery添加/刪除Select的Option項: 語法解釋: 1. $("#select_id").append("<option value='Value'>Text</option>"); //為Select追加一個Option(下拉項) 2. $("#se... 閱讀完整內容
使用jQuery對 select 的操作(本文為網路找到的參考文) 6月 30, 2016 [jQuery] 使用 jQuery 對 select 的操作 1. 取得選擇項目的文字與值 /*----- 單選 -----*/ // 取得被選擇項目的文字 $ ( "#select" ). find ( ":selected" ). text (); // 取得被選擇項目的值 $ ( "#select" ). find ( ":selected" ). val (); /*----- 多選 -----*/ // 使用迴圈取得所有被選擇的項目 $ ( "#select" ). find ( ":selected" ). each ( function () { alert ( this . text ); // 文字 alert ( this .value); // 值 }); 2. 增加項目 $ ( "#select" ). append ( $ ( "<option></option>" ). attr ( "value" , " 值 " ). text ( " 文字 " )); 3. 移除選擇的項目 // 移除選擇的項目 $ ( "#select" ). find ( ":selected" ). remove (); // 移除全部的項目 $ ( "#select option " ). remove (); 4. 移除選擇項目後,防止捲軸移到最上面 // 先取得要移除項目的 index var selectIndex = $ ( "#select" ). find ( ":selected" ). index (); // 移除選擇的項目 $ ( "#select" ). find ( ":selected" ). remove (); // 判斷移除項目後,原先的 inde... 閱讀完整內容
iOS Safari 中點擊事件失效的解決辦法(轉貼) 11月 30, 2016 iOS Safari 中點擊事件失效的解決辦法 問題描述 當使用委託給一個元素添加click事件時,如果事件是委託到 document 或 body 上,並且委託的元素是默認不可點擊的(如 div, span 等),此時 click 事件會失效。 可以使用下面的代碼在 iOS 中進行測試。 <!DOCTYPE html> < html > < head > < meta charset = "UTF-8" > < meta name = "viewport" content = "width=device-width" > < title > iOS click bug test </ title > < style > .container { } .target { display : block; text-align : center; margin : 100px 30px 0 ; padding : 10px 0 ; border : 1px solid #ccc ; } </ style > </ head > < body > < div class = "container" > < div class = "target" > Click Me! </ div > </ div > < script src = "//code.jquery.com/jquery-2.1.4.min.js" > </ script > < scrip... 閱讀完整內容
留言
張貼留言