jQuery文法基礎&選取器

來源:互聯網
上載者:User

標籤:基礎文法   ges   tar   world   hid   ref   sch   share   -1016   

通過 jQuery,您可以選取(查詢,query) HTML 元素,並對它們執行“操作”(actions)。

jQuery 文法執行個體
$(this).hide()
示範 jQuery hide() 函數,隱藏當前的 HTML 元素。
$("#test").hide()
示範 jQuery hide() 函數,隱藏 id="test" 的元素。
$("p").hide()
示範 jQuery hide() 函數,隱藏所有 <p> 元素。
$(".test").hide()
示範 jQuery hide() 函數,隱藏所有 class="test" 的元素。

 

 

jQuery 文法

jQuery 文法是為 HTML 元素的選取編製的,可以對元素執行某些操作。

基礎文法是:$(selector).action()

  • 貨幣符號定義 jQuery
  • 選擇符(selector)“查詢”和“尋找” HTML 元素
  • jQuery 的 action() 執行對元素的操作
樣本

$(this).hide() - 隱藏當前元素

$("p").hide() - 隱藏所有段落

$(".test").hide() - 隱藏所有 class="test" 的所有元素

$("#test").hide() - 隱藏所有 id="test" 的元素

提示:jQuery 使用的文法是 XPath 與 CSS 選取器文法的組合。在本教程接下來的章節,您將學習到更多有關選取器的文法。

 

 

 

 /*************************Deom1**********************************/

 

 /*************************Deom2**********************************/

<!DOCTYPE html><html><head><meta charset="UTF-8"><title>hello World</title><script src="jquery-latest.js"></script><style>.test{height: 200px;width: 200px;background: #33ffca;}</style><script>$(document).ready(function () {$(‘button‘).on(‘click‘,function () {/*$(‘button‘).click(function () {*//*console.info("");*/alert(‘hello World‘);});$(‘.test‘).hide(1000).show(2000);/*動畫隱藏,在現實兩個函數*/});</script></head><body><button>Click Me</button><div class="test"></div></body></html>

 

 

  /*************************Deom3**********************************/

 

 

  /*************************Deom4**********************************/

 

<!DOCTYPE html><html><head><meta charset="UTF-8"><title>簡易表單</title><style>.divBtn{padding-top:5px;}.divBtn ,divCss{border: solid 1px #3598DC;width:50px;}</style><script src="jquery-latest.js"></script><script>$(function () {$(‘button1‘).click(function () {var v1=$(‘#text1‘).val();var r1=$(‘#radio1‘).attr(‘checked‘)?"男":"女";var c1=$(‘#check1‘).attr(‘checked‘)?"已經結婚了":"沒有結婚呐";$(‘.divTip‘).html(v1+‘\n‘+r1+‘\n‘+c1).css(‘display‘,‘block‘);});});</script></head><body><div class="divTitle">請輸入資訊</div><div class="divContent">姓名:<input id="text1" type="text" class="txtCss"><br>性別:<input id="radio1" checked="checked"  type="radio" name="sex" value="男">男  <input id="radio2"  type="radio" name="sex" value="女">女<br>婚否:<input id="check1" type="checkbox"><br><div class="divBtn"><input id="button1" type="button" value="提交" class="btnCss"></div><div id="divTip" class="divTip"></div></div></body></html>

 

 

 /************************* 選取器介紹(有CSS3基礎很容易理解)*********************************/

 

   

 

【作者】:輕輕走143
【出處】:http://www.cnblogs.com/qingqingzou-143/
【聲明】:所有博文標題後加(share)的表示收集的他人優秀文章,其餘的則為原創。歡迎轉載,但請在顯要位置顯示本文連結,並保留本段聲明,否則追究法律責任,謝謝!

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.