获取多个input输入的值,放在多个指定的div上

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<!-- <input type="text" oninput="yz(this)"> -->
<input type="text" name="demo" id="ceshi1">
<input type="text" name="demo" id="ceshi2">
<input type="text" name="demo" id="ceshi3">
<span id="ceshi1-s"></span>
<span id="ceshi2-s"></span>
<span id="ceshi3-s"></span>
<button id="save">点击保存</button>
<script src="jquery-1.8.3.min.js"></script>
<script>
var globalData = {}
$("#save").click(function(){
$("input[name='demo']").each(function(){
globalData[$(this).attr("id")] = $(this).val() || "";
});
for(v in globalData){
$("#"+v+"-s").text(globalData[v])
}
console.log(globalData)
})
</script>
</body>
</html>
posted @ 2018-01-09 17:03  苏小白啊  阅读(1636)  评论(0编辑  收藏  举报