<form id="frm" v-bind:action="flag?'Test.html':'javascript:;'" method="POST" v-on:submit.prevent="smt">
name:<input type="text" id="txtName" /><br>
age:<input type="text" id="txtAge" /><br>
<!-- <input type="submit" value="https://bbs.csdn.net/topics/Submit" onclick="return checkForm()" /> -->
<input type="submit" value="https://bbs.csdn.net/topics/Submit" />
</form>
new Vue({
el: '#frm',
data:
{
flag: false
},
methods:
{
smt: function () {
return checkForm();
}
}
})
function checkForm() {
var txtNameObj = document.getElementById("txtName");
var txtAgeObj = document.getElementById("txtAge");
if (txtNameObj.value.length == 0) {
window.alert("賬號不能為空!");
txtNameObj.focus();
return;
} else if (txtAgeObj.value.length == 0) {
window.alert("年齡不能為空!");
txtAgeObj.focus();
return;
}
this.flag = true;
return true;
}
閑來無事搞搞Vue,發現這樣 提交按鈕怎么點 不觸發,驗證正常,采用這種方式如何修改呢?謝謝了!
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/120747.html
標籤:JavaScript
下一篇:初學者用什么html5軟體才好啊
