jquery標簽選擇器應(yīng)用示例詳解
本文實例為大家分享了jquery標簽選擇器應(yīng)用的具體代碼,供大家參考,具體內(nèi)容如下
1、統(tǒng)一設(shè)置div內(nèi)容
可以用標簽選擇器來選擇所有的 div 元素;
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
<script>
function setdiv()
{
$("div").html('統(tǒng)一設(shè)置內(nèi)容;');
}
</script>
</head>
<body>
<h1></h1>
<div id="div1" style="border:1px solid #0F0;width:150px;height:50px;"></div>
<p></p>
<div id="div2" style="border:1px solid #0F0;width:150px;height:50px;"></div>
<p></p>
<div id="div3" style="border:1px solid #0F0;width:150px;height:50px;"></div>
<p></p>
<div id="div4" style="border:1px solid #0F0;width:150px;height:50px;"></div>
<p></p>
<div id="div5" style="border:1px solid #0F0;width:150px;height:50px;"></div>
<p></p>
<button onclick="setdiv()">設(shè)置內(nèi)容</button>
</body>
</html>


2、jQuery獲取表單的全部數(shù)據(jù)
serialize()方法,
var data= $("form").serialize();
將表單內(nèi)容序列化成一個字符串;
<!DOCTYPE html>
<html>
<head>
<title>表單</title>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
<script>
function getform()
{
var data= $("form").serialize();
alert('表單數(shù)據(jù):'+data);
}
</script>
</head>
<body>
<h1>注冊表單</h1>
<form action="" method="get">
<p>
<label>用戶名:</label>
<input type="text" name="user" />
</p>
<p>
<label>密 碼:</label>
<input type="password" name="password" />
</p>
<p>
<label>性 別:</label>
<input type="radio" name="gender" value="0" /> 男
<input type="radio" name="gender" value="1" /> 女
</p>
<p>
<label>愛 好:</label>
<input type="checkbox" name="like" value="0"> 學(xué)習(xí)
<input type="checkbox" name="like" value="1"> python
<input type="checkbox" name="like" value="2"> 游泳
</p>
<p>
<label>個人介紹:</label>
<textarea name='introduce'></textarea>
</p>
<p>
<label>籍 貫:</label>
<select name="site">
<option value="0">北京</option>
<option value="1">上海</option>
<option value="2">河南</option>
<option value="3">河北</option>
<option value="4">山東</option>
</select>
</p>
<p>
<input type="submit" name="" value="提交1">
<input type="reset" name="" value="重置1">
</p>
</form>
<button onclick="getform()">Get Form</button>
</body>
</html>


$("form"),也是標簽選器;
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
jQuery實現(xiàn)打開網(wǎng)頁自動彈出遮罩層或點擊彈出遮罩層功能示例
這篇文章主要介紹了jQuery實現(xiàn)打開網(wǎng)頁自動彈出遮罩層或點擊彈出遮罩層功能,涉及jQuery事件響應(yīng)及窗口元素屬性的相關(guān)操作技巧,需要的朋友可以參考下2017-10-10
EasyUI的DataGrid每行數(shù)據(jù)添加操作按鈕的實現(xiàn)代碼
今天做項目的時候,想在easyui的datagrid每一列數(shù)據(jù)后邊都加上一個操作按鈕,怎么實現(xiàn)此功能呢?下面小編給大家?guī)砹薊asyUI的DataGrid每行數(shù)據(jù)添加操作按鈕的實現(xiàn)代碼,需要的朋友參考下吧2017-08-08
jQuery實現(xiàn)固定在網(wǎng)頁頂部的菜單效果代碼
這篇文章主要介紹了jQuery實現(xiàn)固定在網(wǎng)頁頂部的菜單效果,通過jquery頁面scroll事件及邊距計算實現(xiàn)網(wǎng)頁的菜單固定效果,非常簡單實用,需要的朋友可以參考下2015-09-09
jQuery 獲取頁面li數(shù)組并刪除不在數(shù)組中的key
這篇文章主要介紹了jQuery 獲取頁面li數(shù)組并刪除不在數(shù)組中的key 的相關(guān)資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2016-08-08
jquery中關(guān)于bind()方法的使用技巧分享
這篇文章主要給大家分享了jquery中關(guān)于bind()方法的使用技巧,文中介紹的非常詳細,對大家具有一定的參考價值,需要的朋友們下面來一起看看吧。2017-03-03

