使用jQuery獲得內(nèi)容以及內(nèi)容的屬性
更新時間:2015年02月26日 10:58:09 投稿:hebedich
本文給大家分享的是一則使用jQuery獲得內(nèi)容以及內(nèi)容的屬性的方法和示例,非常實用,推薦給大家。
復(fù)制代碼 代碼如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="js/jquery.js"></script>
</head>
<style>
body{font-family: "微軟雅黑";width: 980px; margin: 0 auto; text-align: center;}
.box{
width: 300px;
height: 300px;
background: green;
border: 1px solid #e6e6e6;
line-height: 200px;
position: absolute;
}
button{
border: none;
background: green;
width: 125px;
height: 50px;
line-height: 50px;
color: #fff;
font-size: 16px;
margin-top: 50px;
font-family: "微軟雅黑";
}
</style>
<body>
<button id="btn1">顯示text</button>
<button id="btn2">顯示html</button>
<button id="btn3">顯示輸入內(nèi)容</button>
<p id="text">這是要顯示<b>粗體</b>的節(jié)奏</p>
<br />
<input id="input" value="買房子">
<script>
$(document).ready(function(){
$("#btn1").click(function(){
alert("Text: " + $("#text").text());
});
$("#btn2").click(function(){
alert("HTML: " + $("#text").html());
});
$("#btn3").click(function(){
alert("Value: " +$("#input").val());
});
});
</script>
</body>
</html>
Tips:
1、點擊事件節(jié)點的選擇 #botton
2、alert 的代碼規(guī)則 ("Value: " + $("#id").html)
今天的分享就先到這里了,后續(xù)我們還將持續(xù)更新一些新的jQuery實例。
相關(guān)文章
省市區(qū)三級聯(lián)動jquery實現(xiàn)代碼
這篇文章主要為大家詳細紹了省市區(qū)三級聯(lián)動jquery實現(xiàn)代碼,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-10-10
jquery+json實現(xiàn)數(shù)據(jù)列表分頁示例代碼
該實例中,新聞數(shù)據(jù)列表未使用表格顯示,下面有個不錯的示例完美實現(xiàn)實現(xiàn)數(shù)據(jù)列表分頁,感興趣的朋友不要錯過2013-11-11
jQuery實現(xiàn)單擊按鈕遮罩彈出對話框(仿天貓的刪除對話框)
單擊刪除按鈕或者登陸按鈕后,彈出對話框問你是否刪除或者彈出一個登陸對話框,本文使用jquery來實現(xiàn)這種效果,需要的朋友可以參考下2014-04-04

