有關多選與單選(轉載) 取得連結 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... 閱讀完整內容
彈跳視窗iframe的運用 6月 01, 2016 要簡單的使用手機形式的iframe彈出視窗 一般要使用的話,都需要寫很多語法,在這邊可以使用 fancybox這個jQuery的外掛 使用時,記得加入class="iframe",加入之後,要在在畫面上設定如下 $ ( '.iframe' ). fancybox ({ width : '100%' , height : '70%' , titlePosition : 'outside' }); 注意的是,如果畫面是動態生成的,記得在動態畫面生成之後,立刻加入這行。 一開始使用的時候,發現怎麼按都不會出現彈跳視窗,但是在畫面上寫死的時候,就會work 後來想到應該是順序的問題(HTML上寫死的畫面已經載入,動態生成算是後來才追加的),因此如同作多國語系的時候一樣, 在畫面生成之後加入即可動作。 而如果在ifrmae的畫面中要刷新後方的父頁面(例如在子視窗編輯評論,編輯完成後回到父視窗) 可以加入以下兩行 關閉該子視窗 parent . jQuery . fancybox . close (); (填入原本父視窗的網址) 即可做到關閉子視窗同時刷新父視窗 window . parent . location = "evaluation.html" ; PS. 如果沒有加入parent而直接使用window.location = "OOOO.html";的話,會變成刷新子視窗 閱讀完整內容
留言
張貼留言