使用jQuery獲得內(nèi)容以及內(nèi)容的屬性
更新時(shí)間:2015年02月26日 10:58:09 投稿:hebedich
本文給大家分享的是一則使用jQuery獲得內(nèi)容以及內(nèi)容的屬性的方法和示例,非常實(shí)用,推薦給大家。
復(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、點(diǎn)擊事件節(jié)點(diǎn)的選擇 #botton
2、alert 的代碼規(guī)則 ("Value: " + $("#id").html)
今天的分享就先到這里了,后續(xù)我們還將持續(xù)更新一些新的jQuery實(shí)例。
相關(guān)文章
jQuery--遍歷操作實(shí)例小結(jié)【后代、同胞及過濾】
這篇文章主要介紹了jQuery 遍歷操作,結(jié)合實(shí)例形式詳細(xì)分析了jQuery針對后代、同胞及過濾遍歷的相關(guān)函數(shù)、操作技巧與使用注意事項(xiàng),需要的朋友可以參考下2020-05-05jQuery實(shí)現(xiàn)點(diǎn)擊某個(gè)div打開層,點(diǎn)擊其他div關(guān)閉層實(shí)例分析(阻止冒泡)
這篇文章主要介紹了jQuery實(shí)現(xiàn)點(diǎn)擊某個(gè)div打開層,點(diǎn)擊其他div關(guān)閉層的方法,結(jié)合實(shí)例形式分析了jQuery兩種阻止冒泡實(shí)現(xiàn)彈出層的處理技巧,需要的朋友可以參考下2016-11-11jquery輪播的實(shí)現(xiàn)方式 附完整實(shí)例
這篇文章主要介紹了jquery輪播的實(shí)現(xiàn)方式,文中分享了jQuery輪播完整實(shí)例,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-07-07