我有输入文字和按钮保存。这是元素生成服务器。我想要覆盖功能,它调用按钮保存。这是我的HTML代码的一部分:
Phone: < input type = "text"
name = "Phone"
title = "title1"
value = "(999) 999-9999" > < input class = "ms-ButtonHeightWidth"
type = "button"
target = "_self"
accesskey = "O"
onclick = "if (!PreSaveItem()) return false;WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("
ctl00$ctl19$g_491cf573_1d26_479b_ba3e_73aecb248dcb$ctl00$toolBarTbl$RightRptControls$ctl00$ctl00$diidIOSaveItem ", "
", true, "
", "
", false, true))"
value = "Save" >
你能帮我在JQuery上编写这样的函数:
<script type="text/javascript">
$(document).ready(function () {
var buttonSave = $('[value="Save"]');
var tempOnClick = buttinSave.Onclick;
buttinSave.Onclick = Validate();
function Validate() {
if ($('[title="title1"]').text.lenght == 14) {
tempOnClick.click();
} else {
alert("The field not valid!");
}
}
});
</script>
我知道,当用户点击按钮保存时,调用我的功能验证如果输入文本框有14个符号调用默认功能。有可能吗?
答案 0 :(得分:1)
var temp = $('input[value=Save]').click;
$('input[value=Save]').click(Validate);
function Validate() {
if ($('input[title=title1]').val().length != 14) {
alert("The field not valid!");
}else {
temp();
}
}
另外,在编码时检查变量的命名!祝你好运!