2017年11月21日 星期二

[JS]JQUERY 取值 設定值 用法

JQUERY 取值 設定值 用法
TextBox (最基本的)
  1. Html定義
  2.  
  3. 取值
  4. $('input[name="text1"]').val();
  5. 取自訂屬性
  6. $('input[name="text1"]').attr("test");
  7. 設定值
  8. $('input[name="text1"]').val("text123");
  9. 設定自訂屬性
  10. $('input[name="text1"]').attr("test","測試用123");
Checkbox
  1. Html定義
  2.  
  3.  
  4. 取值
  5. $('input[name="check1"]').val()
  6. 取自訂屬性
  7. $('input[name="check1"]').attr("test")
  8. 取得是否被勾選
  9. $('input[name="check1"]').prop("checked");
  10. 設定值
  11. $('input[name="check1"]').val("text123");
  12. 設定自訂屬性
  13. $('input[name="check1"]').attr("test","測試用123");
  14. 設定勾選
  15. $('input[name="check1"]').prop("checked",true);
RadioButton
  1. Html定義
  2.  
  3. 取得現在選取的值
  4. $('input[name="radio1"]:checked').val()
  5. 取現在選取的自訂屬性
  6. $('input[name="radio1"]:checked').attr("text")
  7. 設定測試為勾選狀態
  8. $('input[name="radio1"][value="0"]').prop("checked",true);
  9. 取得此欄位是否為勾選狀態
  10. $('input[name="radio1"][value="0"]').is(':checked')
Dropdownlist
  1. Html定義
  2.  
  3.  
  4. 取得現在選取的值
  5. $('select[name="select1"]').val()
  6. 取得現在選取的自訂屬性 (兩種都可以)
  7. $('option:selected', 'select[name="select1"]').attr('test');
  8. $( 'select[name="select1"] :selected').attr('test');
  9. 設定現在選取的值 (兩種效果一樣)
  10. $('select[name="select1"]').val("val1");
  11. $('select[name="select1"]').val("1");
  12. 取得此選項是否為勾選狀態
  13. $('select[name="select1"] option[value="val2"]').is(':selected');
  14. 取所有option 看是否為勾選
  15. $('select[name="select1"] option').each(function(){
  16. alert($(this).is(':selected'));
  17.  
  18. });
基本的大致在此 有想到再補充 使用的JQUERY版本為1.8.3 後面的版本應該也可以用 參考來源:http://white1027.blogspot.tw/2013/06/js-jquery.html

沒有留言:

張貼留言