<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0"/>
<title>获取标签值</title>
<script type="text/javascript" src="jquery-2.2.4.min.js"></script>
<script type="text/javascript" src="initFontSize.js"></script><!-- 初始化字体 -->
<style type="text/css">
span,label,div,html,body{
margin: 0;padding: 0;
}
.span,.label{
display: inline-block;
width: 8rem;
height: 2rem;
}
.input{
display: inline-block;
width: 10rem;
background-color: #e3e3e3;
border-radius: 0.2rem;
margin-left: 3rem;
}
</style>
</head>
<body>
<div class="div1">
<span>666666</span>
</div>
<label class="label">这是label</label>
<span class="span">这是span</span>
<input id="input" class="input" type="text" name="text" value="44">
<input class="input" type="text" name="text" value="555">
<script type="text/javascript">
/*
获取input里的值
*/
console.log($("#input").val())
console.log($(".input")[1].value)
/*
修改input里的值
*/
$("#input").val("66666")
$(".input")[1].value = "修改了吗?"
/*
获取span标签里面的值
*/
console.log($(".span").html()) //.html() 方法返回或设置被选元素的内容 (innerHTML)
console.log($(".span").text()) //.text() 方法方法设置或返回被选元素的文本内容。
console.log($(".span")[0].innerHTML)
var $span = $("span")
for (var i = 0; i < $span.length; i++) {
console.log(i,$span[i].innerHTML)
}
</script>
</body>
</html>