分類彙整:Jquery

jqGrid:使用cell value設定文字顏色

$("#mylist").jqGrid({ … colModel:[ ... {name:'value', width:100, align:'right', cellattr:valueAttr, ....}, ... ], … }); function valueAttr(rowId, cellValue, rawObject, cm, rdata) { if (cellValue < 0) { return ‘ style="color: red"‘; } else { return ‘ style="color: green"‘; } }

發表於 Jquery | 發表迴響

Add additional data to $form.serialize()

$.ajax({ type: ‘post’, url: ‘page.php’, data: $form.serialize() + ‘&data=’ + JSON.stringify(otherData), dataType : ‘json’ })

發表於 Javascript, Jquery | 發表迴響

讓 checkbox 變為單選

<input type="checkbox" name="myCheckBox" value="checkBox1″>checkBox1 <input type="checkbox" name="myCheckBox" value="checkBox2″>checkBox2 <input type="checkbox" name="myCheckBox" value="checkBox3″>checkBox3 <script type="text/javascript"> <!– $(document).ready(function(){ $("input[name=myCheckBox]").click( function () { var Selected = $(this).val(); $("input[name=myCheckBox]").each(function(i){ if($(this).val() == Selected) $(this).prop("checked", true); else $(this).prop("checked", false); }); }); }); –> </script>  

發表於 Jquery | 發表迴響

jQuery 事件 – select() 方法

觸發 select 事件 語法:$(selector).select(); 例一: $("input").select(function(){ }); 例二: $("input[type=text]").on(‘focus‘, function() { $(this).mouseup(function(e){ e.preventDefault(); });//取消 on focus 觸發後的動作   $(this).css(‘background-color’,’#FFFFFF’).select(); }).on(‘blur‘, function() { $(this).css(‘background-color’,’#E8E8E8′); });

發表於 Jquery | 發表迴響

jQuery:表單Radio元素哪個被選取的方法

$(‘input[name=Radio元素使用的name值]:checked’).val();  

發表於 Jquery | 發表迴響

使用jQuery複製表單元素

<script type="text/javascript"> $("#addOtherCat").click(function() { $("#cat_id").clone().attr(‘name’, ‘other_cat[]‘).insertAfter(this); }); </script> <select name="cat_id" id="cat_id"> <option value="" >請選擇…</option> <option value="1″ >A</option> <option value="2″ >B</option> <option value="3″ >C</option> </select> <input type="button" value="增加" id="addOtherCat" name="addOtherCat">

發表於 Jquery | 發表迴響

jQuery $(document).ready(fn)與$(window).load(fn)

二者的差異: $(document).ready(fn):在網頁HTML載入後即觸發。 $(window).load(fn):等到網頁HTML標籤中引用的圖檔、內嵌物件(如Flash)、Frame等都載入後才會觸發。

發表於 Jquery | 發表迴響

jQuery:取值

textbox $("#text").val();//取值 $("#text").val("Hello World");//給值 radiobox 取得選中值:$("input[name=gender]:checked").val(); 使第N個radiobox被選中: $("input[type=radio]").eq(N).prop("checked",true); 觸發click事件: $("input[type=radio]").eq(N).trigger(‘click’); $("input[type=radio]").eq(N).attr("checked",true).trigger(‘click’); 取得多組 (:enabled, :disabled,:selected都同方法) $("input:checked").each(funciton(){…}); $("select option:selected").each(function () {…}); checkbox if($("#checkbox").prop("checked"));//判斷是否勾選 $("#checkbox").attr("checked",true);//勾選 $("#checkbox").attr("checked",false);//不勾選 var checkedValue = $(‘input:checkbox[name=leave_type][checked=checked]‘).map(function(){ return $(this).val(); }).get().join(‘,’); //取值 var mode = $("#mode").prop("checked") ? 1 : 0; var enable … 繼續閱讀

發表於 Jquery | 發表迴響