Jquery使用小結,jquery小結

來源:互聯網
上載者:User

Jquery使用小結,jquery小結

這周都在做前端頁面的開發,用了Jquery知識比較多,方便以後使用,就做一個小總結吧。

清空某個元素下面的所有子項目:

$("#tickey_content").empty();

迴圈數值:

$.each(contents, function(i, item){       createContent(item.userName, item.createDate, item.content, item.filePath, item.fileName, item.role); }); 
擷取Label元素裡面的文本:

$("#role").text()

設定label元素裡面的文本:

<pre name="code" class="javascript">$("#role")<span style="font-family: Arial, Helvetica, sans-serif;">.html(userName);</span>

擷取Textarea元素裡面的文本:

$("#reply").val();
清空Textarea元素裡面的文本:

$("#reply").val("");
Jquery可能某個元素:

$("#content_template").clone();

擷取某個元素下面的第一個子項目:

templateDiv.children(":first");

擷取某個元素的下一個元素:

templateDiv.next();
擷取某個元素下面的最後一個元素:

contentTemplate.children(":last");

刪除元素的某個屬性,比如Id:

templateDiv.removeAttr("id"); 
給元素添加某個CSS屬性:

templateDiv.css('display','block');

給某個元素添加一個class屬性:

divElement.addClass("engineerStyle");

給a標籤添加href屬性:

$("#aElement").attr("href", "${ctx}"+filePath+fileName);
在某個元素下面添加一個新的元素:

$("#tickey_content").append(templateDiv);
向某個元素下面添加一個元素到最前面:

divElement.prepend(content);

JS字串判斷是否包含某個字元:

role.indexOf('工程師')>=0











聯繫我們

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