標籤:基礎文法 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文法基礎&選取器