2017年11月21日 星期二

[JS]JQUERY 取值 設定值 用法

JQUERY 取值 設定值 用法
TextBox (最基本的)
Html定義
 

取值
$('input[name="text1"]').val();
取自訂屬性
$('input[name="text1"]').attr("test");
設定值
$('input[name="text1"]').val("text123");
設定自訂屬性
$('input[name="text1"]').attr("test","測試用123");
Checkbox
Html定義


取值
$('input[name="check1"]').val()
取自訂屬性
$('input[name="check1"]').attr("test")
取得是否被勾選
$('input[name="check1"]').prop("checked");
設定值
$('input[name="check1"]').val("text123");
設定自訂屬性
$('input[name="check1"]').attr("test","測試用123");
設定勾選
$('input[name="check1"]').prop("checked",true);
RadioButton
Html定義



取得現在選取的值
$('input[name="radio1"]:checked').val()
取現在選取的自訂屬性
$('input[name="radio1"]:checked').attr("text")
設定測試為勾選狀態
$('input[name="radio1"][value="0"]').prop("checked",true);
取得此欄位是否為勾選狀態
$('input[name="radio1"][value="0"]').is(':checked')
Dropdownlist
Html定義


取得現在選取的值
$('select[name="select1"]').val()
取得現在選取的自訂屬性 (兩種都可以)
$('option:selected', 'select[name="select1"]').attr('test');
$( 'select[name="select1"] :selected').attr('test');
設定現在選取的值 (兩種效果一樣)
$('select[name="select1"]').val("val1");
$('select[name="select1"]').val("1");
取得此選項是否為勾選狀態
$('select[name="select1"] option[value="val2"]').is(':selected');
取所有option 看是否為勾選
$('select[name="select1"] option').each(function(){
    alert($(this).is(':selected'));

});
基本的大致在此 有想到再補充 使用的JQUERY版本為1.8.3 後面的版本應該也可以用 參考來源:http://white1027.blogspot.tw/2013/06/js-jquery.html

沒有留言:

張貼留言