无法通过asp.net中的javascript获取价值 [英] Unable to get value through javascript in asp.net
本文介绍了无法通过asp.net中的javascript获取价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我点击按钮时,页面刷新,我没有得到文本框值。
When I click on button just page refresh and I didn't get textbox value.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="TestToOnFocus.test" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script src="test.js"></script>
<title>Test</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtName" runat="server" ClientIDMode="Static"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="return test();"/>
</div>
</form>
</body>
</html>
function test() {
var name = document.getElementById("<%= txtName.ClientID %>").value;
if(name=="")
{
alert("Please");
}
else
{
alert(name);
}
}
推荐答案
试试这个 -
Try this-
function test() {
var name = document.getElementById("<%= txtName.ClientID %>").value;
if(name=="")
{
alert("Please");
return false;
}
else
{
alert(name);
return true;
}
}
<script language ="javascript" type ="text/javascript" >
function validate()
{
if(document .getElementById("<%=txtName.ClientID%>").value=="Select")
{
alert ("Please ");
document.getElementById("<%=txtName.ClientID%>").focus();
return false ;
}
}
</script>
http://www.aspsnippets.com/Articles /TextBox-Validation-using-JavaScript.aspx [ ^ ]
下载Js文件并将其拖到你的项目
http://www.aspsnippets.com/Articles/TextBox-Validation-using-JavaScript.aspx[^]
Download Js file and drag it to ur project
试试
try
document.getElementById("<%= txtName.ClientID %>").val();
而不是
instead of
document.getElementById("<%= txtName.ClientID %>").value;
这篇关于无法通过asp.net中的javascript获取价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文