87,993
社区成员
发帖
与我相关
我的任务
分享 $(":input").blur(function(){
$(this).val(this.value);
alert($(this).val());
})
F12看console,它提示说:this.val()有问题
(个人感觉value是js的,val()是jq的,你混用就报错了)
<!doctype html>
<html lang="zh-cn">
<head>
<title></title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no,minimal-ui"/>
</head>
<body>
<table>
<tr>
<td><input type="text" id="quarterly-1-hours" name="quarterly-1-hours" value="0001-0200"/></td>
<td><input type="text" id="quarterly-1-hours" name="quarterly-1-hours" value="0001-0200"/></td>
<td><input type="text" id="quarterly-1-hours" name="quarterly-1-hours" value="0001-0200"/></td>
</tr>
</table>
<button style="background:#4169E1;color:white;border:none;height:200;" type="button" id="batch-save-btn">Save</button>
<button style="background:#4169E1;color:white;border:none;height:200;" type="button" id="batch-view-btn">View Previous Data</button>
<result style="display:block;"></result>
<script type="text/javascript" src="http://www.w3school.com.cn/jquery/jquery.js"></script>
<script>
var viewBtn = $("#batch-view-btn");
var saveBtn = $("#batch-save-btn");
saveBtn.click(function(){
var saveData = $("input[name='quarterly-1-hours']").toArray().map(o => o.value);
localStorage["data"] = saveData;
});
viewBtn.click(function(){
var saveData = localStorage["data"];
saveData && $("result").text(saveData);
});
</script>
</body>
</html>
<body>
<input type="text" class="zz" value="0001-0201"/>
<input type="text" class="zz" value="0001-0202"/>
<input type="text" class="zz" value="0001-0203"/>
<script src="jquery-3.1.1.min.js"></script>
<script>
$(".zz").blur(function(){
tmp=$(this).val();
alert(this.value+"||"+tmp);
});
</script>
</body>[/quote]
问题是我希望关闭页面下次再打开页面,页面上显示的是我修改过的值,但是现在这样写,保存不下来,这个问题怎么解决,不使用数据库的情况下
<!doctype html>
<html lang="zh-cn">
<head>
<title></title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no,minimal-ui"/>
</head>
<body>
<table>
<tr>
<td><input type="text" id="quarterly-1-hours" name="quarterly-1-hours" value="0001-0200"/></td>
<td><input type="text" id="quarterly-1-hours" name="quarterly-1-hours" value="0001-0200"/></td>
<td><input type="text" id="quarterly-1-hours" name="quarterly-1-hours" value="0001-0200"/></td>
</tr>
</table>
<button style="background:#4169E1;color:white;border:none;height:200;" type="button" id="batch-save-btn">Save</button>
<button style="background:#4169E1;color:white;border:none;height:200;" type="button" id="batch-view-btn">View Previous Data</button>
<result style="display:block;"></result>
<script type="text/javascript" src="http://www.w3school.com.cn/jquery/jquery.js"></script>
<script>
var viewBtn = $("#batch-view-btn");
var saveBtn = $("#batch-save-btn");
saveBtn.click(function(){
var saveData = $("input[name='quarterly-1-hours']").toArray().map(o => o.value);
viewBtn.data("data",saveData);
});
viewBtn.click(function(){
var saveData = viewBtn.data("data");
saveData && $("result").text(saveData.join(","));
});
</script>
</body>
</html>
<body>
<input type="text" class="zz" value="0001-0201"/>
<input type="text" class="zz" value="0001-0202"/>
<input type="text" class="zz" value="0001-0203"/>
<script src="jquery-3.1.1.min.js"></script>
<script>
$(".zz").blur(function(){
tmp=$(this).val();
alert(this.value+"||"+tmp);
});
</script>
</body>