使用jQuery获得内容以及内容的属性
<!DOCTYPEhtml>
<html>
<head>
<metacharset="utf-8">
<title></title>
<scriptsrc="js/jquery.js"></script>
</head>
<style>
body{font-family:"微软雅黑";width:980px;margin:0auto;text-align:center;}
.box{
width:300px;
height:300px;
background:green;
border:1pxsolid#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>
<buttonid="btn1">显示text</button>
<buttonid="btn2">显示html</button>
<buttonid="btn3">显示输入内容</button>
<pid="text">这是要显示<b>粗体</b>的节奏</p>
<br/>
<inputid="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、点击事件节点的选择#botton
2、alert的代码规则 ("Value:"+$("#id").html)
今天的分享就先到这里了,后续我们还将持续更新一些新的jQuery实例。