jQuery表單域屬性過濾器用法分析,jquery表單域過濾器

來源:互聯網
上載者:User

jQuery表單域屬性過濾器用法分析,jquery表單域過濾器

本文執行個體講述了jQuery表單域屬性過濾器用法。分享給大家供大家參考。具體分析如下:

表單內包含各種各樣的表單域,使用表單域屬性選取器可以很好的擷取已被選中的選項按鈕,複選框以及清單項目,也可以根據是否可用從文檔中尋找表單域。

1. :checked選取器

用於選擇所有被選中的表單域。格式:複製代碼 代碼如下:$("selector:checked")可以是input,radio和checkbox

2. :enabled選取器

用於選擇所有可用的表單域,格式:複製代碼 代碼如下:$("selector:enabled")

3. :disabled選取器

用於選擇所有被禁用的表單域,格式:複製代碼 代碼如下:$("selector:disabled")

4. :selected選取器

用於從列表框選擇所有選中的option元素,格式:複製代碼 代碼如下:$("selector:selected")

5. :hidden選取器

用於選擇所有的隱藏元素
複製代碼 代碼如下:$("selector:hidden")

6. :visible選取器

用於選擇所有的可見元素

簡單樣本:
複製代碼 代碼如下:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>表單域屬性過濾選取器應用樣本</title> 
<script type="text/javascript" src="jquery-1.7.min.js"></script> 
<script type="text/javascript"> 
$(document).ready(function(){ 
     $("input:checked").css("border", "1px solid red"); 
     $("input:disabled").css("background", "#FCF"); 
     $("input:enabled").val("可用文字框"); 
});
</script> 
</head> 
<body> 
<h3 align="center">表單域屬性過濾選取器應用樣本</h3> 
<table width="602" height="81" border="1"> 
  <tr> 
    <td width="118">複選框:</td> 
    <td width="443"><input type="checkbox" checked="checked" />被選中的複選框 
    <input type="checkbox" checked="checked" />被選中的複選框 
    <input type="checkbox" />沒有被選中的複選框 
    </td> 
  </tr> 
  <tr> 
    <td>可用文字框:</td> 
    <td><input type="text"/></td> 
  </tr> 
  <tr> 
    <td>不可用文字框:</td> 
    <td><input type="text" disabled="disabled" /></td> 
  </tr> 
   <tr> 
    <td>下拉式清單</td> 
    <td> 
    <select name="test" > 
     <option>浙江</option> 
     <option>湖南</option> 
     <option selected="selected">北京</option> 
     <option selected="selected">天津</option> 
     <option>廣州</option>  
     <option>湖北</option> 
  </select> 
  </td> 
  </tr> 
</table> 
</body> 
</html>

希望本文所述對大家的jQuery程式設計有所協助。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.