Javascript验证返回false仍然是页面回发? [英] Javascript validation return false still page was postback?
本文介绍了Javascript验证返回false仍然是页面回发?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对按钮OnClintclick事件上的文件上传控件进行了javascript验证。
javascript函数返回false仍然按钮点击事件触发...当javascript返回false时如何避免回发?
thankyou
我尝试过:
我的js代码是
i have javascript validation for file upload control on button OnClintclick event.
javascript function return false still button click event firing...how to avoid postback when javascript returns false?
thankyou
What I have tried:
My js code is
<script language="javascript" type="text/javascript">
function checkRequiredFields() {
var imgpath = document.getElementById('FileUpload1').value;
if (imgpath == "") {
alert("please select a file");
document.file.FileUpload1.focus();
return false;
}
else {
alert("success");
}
var array = ['zip', 'jpg', 'jpeg', 'doc', 'docx', 'xls', 'xlsx', 'pdf', 'txt'];
var xyz = document.getElementById("FileUpload1");
var Extension = xyz.value.substring(xyz.value.lastIndexOf('.') + 1).toLowerCase();
if (array.indexOf(Extension) <= -1) {
alert("Selected file does not meet the upload criteria.");
document.form.FileUpload1.focus();
return false;
}
else {
alert("success");
}
}
</script>
按钮控制
button control is
<asp:Button ID="CaseAttachments_btnUpload" runat="server" CssClass="FA_TextButton" Text="Upload" OnClientClick="return checkRequiredFields();" OnClick="MyButton_Click" />
推荐答案
只要javascript代码中出现错误(语法),就会发生此错误错误或运行时错误)
如果有错误(语法或运行时间
),如果没有错误,它将返回true
。
尝试检查以下内容:
放置<$ c javascript 函数的第一行中的$ c>调试器
This Error will happen whenever there is an error in the javascript code ( syntax error or run time error )
If there is an error (Syntax or run time
), and if unhanded it will return astrue
.
Try to do check the below :
Place adebugger
in the first line of your javascript function
function checkRequiredFields() {
debugger; // debugger to stop code execution on this particular line
var imgpath = document.getElementById('FileUpload1').value;
要调试,您可以通过启用开发人员工具来使用Chrome浏览器或IE,这可以通过
- Chrome - 按 F12 或菜单 - >工具(更多工具) - >打开开发人员工具。开发人员工具
- IE - 按 F12
- Chrome- Open the developer tools by pressing F12 or Menu->Tools (More tools) -> Developer tools
- IE - Press F12
To debug you can either use Chrome browser or IE by Enabling the Developer Tools, which can be done by
这篇关于Javascript验证返回false仍然是页面回发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文