我有一个调查,“Onclick”应该验证必填字段是否已填写,存储到本地存储,并导航到确认页面。当未填写 1 required 时,它可以工作并且不会在本地存储,但是它不会提示用户需要填写哪个字段。因此,从技术上讲,它只是在验证并没有按照预期的方式提示用户。
目前:
<label>Hospital*:</label>
<input required title="Hospital is required!" name="MainHospital" type="text" />
js
function clicked() {
if (confirm('Are you sure you want to submit? You will not be able to go back.')) {
form.submit();
} else {
return false;
}
}
$('form').submit(function() {
var person = $("#FirstName").val() + "." + $('#LastName').val();
$('input, select, textarea').each(function() {
var value = $(this).val(),
name = $(this).attr('name');
localStorage[person + "." + name] = value;
window.location.href = "Confirmation.html";
console.log('stored key: '+name+' stored value: '+value);
});
});
这是整个 if 有助于显示我的问题:http: //jsfiddle.net/Axhn4/