淺析jQuery選取器,jquery選取器

來源:互聯網
上載者:User

淺析jQuery選取器,jquery選取器

說是選取器的淺析,其實這些也是我們最常用的選取器。


1、$("   ") 這個是基礎,也就是無論jQuery哪種選取器都是依賴於這種格式。

例如:$("p") 、$("div") 等選擇所有的p標籤 或是 所有的div的標籤 返回的是一個 字串類型的數組   var   arr[]

2、$(".class"); class 選取器

3、$("#id ");Id 選取器

4、比較特殊一點但是經常會用的就是select 下拉式清單方塊

       例如: 代碼顯示

.jsp代碼

<span style="font-family:Microsoft YaHei;font-size:14px;"> <select id="testTypeId"  style="width:150px">       <option value="">--請選擇--</option><c:forEach var="country" items="${testTypelist }" ><option value="${country.dict_item_id}" >${country.dict_item_name}</option></c:forEach></select> </span>
script代碼:

<span style="font-family:Microsoft YaHei;font-size:14px;"><script type="text/javascript">function addPos() {var testTypeName= $('#testTypeId option:selected').text().trim();// 這個是${country.dict_item_name}值(option的值)        alert(testTypeName);       // 這個是${country.dict_item_name}值(option的值)       alert($("#testTypeId").find('option:selected').text());       //這個是value="${country.dict_item_id}" 值(value的值) alert($('#testTypeId').val());</script></span>
先就寫這麼多吧,以後在編輯 希望大家多多指點

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.