本文介绍了我的javascript代码不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script type ="text/javascript">
function validate() {
var firstname = document.getElementById("TextBox1").value;
if( firstname == )
{
alert( " fill");
}
}
</script>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="NAME"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" onclientclick="validate();"
Text="Button" />
</div>
</form>
</body>
</html>
推荐答案
if( firstname == )
尝试
Try
if( firstname == '')
而不是......
<html>
<body>
<script type='text/javascript'>
function Empty(element, AlertMessage){
if(element.value.trim()== ""){
alert(AlertMessage);
element.focus();
return false;
}
alert("Textbox Validation: Successful.")
return true;
}
</script>
<form>
Enter any value or left blank: <input type='text' id='txtBox'/>
<input type='button'
/>
</form>
</body>
</html>
这篇关于我的javascript代码不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!