HTML代码/文本/值
获得元素所有内容 html()
var con1=$("#title").html();
alert(con1);
获得元素所有纯文本内容 text()
var con2=$("#title").text();
alert(con2);
设置元素的内容html(a)
$("#title").html('我是新设置的1');
设置元素的纯文本内容text(a)
$("#title").text('我是新设置的22');
乾坤大挪移将ab两个div换值
获得表单的value val()
var con1=$("#uname").val();
alert(con1)
设置表单的value val(a)
con1=$("#uname").val(88888);<html>
<head>
<style type="text/css">
*{font-size: 20px;}
#hd1{
height: 200px;
width: 200px;
border: solid 1px green;
}
#hd2{
height: 200px;
width: 200px;
border: solid 1px yellow;
}
</style>
<!--引入jquery文件 -->
<script src="jquery.js"></script>
<script type="text/javascript">
$(function(){
$("#bt1").click(function(){
var temp=$('#hd1').html();
$('#hd1').html($('#hd2').html());
$('#hd2').html(temp);
})
})
</script>
</head>
<body>
<input type="button" value="乾坤大挪移" id="bt1">
</br></br>
<div id="hd1">我是小公主</div>
<div id="hd2"><img src="dog.jpg" width="100px" height="100px"></div>
</body>
</html>