我的javascript代码不起作用 [英] my javascript code is not working

查看:75
本文介绍了我的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>
&nbsp;&nbsp;
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
&nbsp;
        <asp:Button ID="Button1" runat="server" onclientclick="validate();"

            Text="Button" />

    </div>
    </form>
</body>
</html>

推荐答案

快速看一下这可能就是这样:

A quick look says it's probably this bit:
if( firstname == )

尝试

Try

if( firstname == '')

而不是......


这不是有效的Javascript代码。缺少'=='运算符的右操作数。



-SA
This is not valid Javascript code. Right operand of the '==' operator is missing.

—SA


你可以试试这个

You can try this
<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代码不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆