[英]Javascript using asp.net
我有一个登录页面,其中包含两个文本框,一个是用户名,密码和一个按钮,如果那时两个文本框为空,那么如果在那个时候输入了任何值,那么我如何避免回传到buuton中,而仅使用回发指针,必需的fiekd验证程序javascript中可以使用任何方法。
yes according to me you can do one thing is to check for the check box values when clicking button 是的,根据我的看法,您可以做一件事是单击按钮时检查复选框的值
html part html部分
<asp:button onclientClick="return onclick()" id="btnLogin" runat="server" >
or in cs file 或在cs文件中
btnLogin.attribute.Add("onclick","return onclick()");
function onclick()
{
var bool = true;
if($("#username").val()==="")//document.getElementById("username").value
bool = false;
if($("#password").val()==="")//document.getElementById("password").value
bool = false;
return bool;
}
use commented part to get value if you are not using jquery 如果您不使用jQuery,请使用注释部分来获取价值
use jquery and the following code also do what you want 使用jQuery,以下代码也可以满足您的要求
$(document).ready(function() {
// Save Button
$('#<%= TestButton.ClientID %>').click(function(e) {
var username = $('#<%= usernameTextBox.ClientID %>').val();
var email = $('#<%= passwordTextBox.ClientID %>').val();
if ( username.length == 0 || email.length == 0 ||) {
e.preventDefault();
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.