javascript在mozilla中不起作用,但在其他浏览器中工作

时间:2010-02-22 17:56:45

标签: c# .net asp.net javascript asp.net-2.0

使用的技术: - Asp.Net 2.0

代码: - 见下文
说明: - 下面给出的hello代码在ie等工作正常但在所有mozila版本中都不起作用.javascript很容易设置两个textbox的值。你很容易理解。

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="javascript_test.aspx.cs" Inherits="javascript_test" %>

<!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" >
  <script type ="text/jscript">

var _txtamount;
var _txtins;
var _txtinsamount;

   function test() 
   {               
          var temp;
         _txtamount = document.getElementById("txtamount");
         _txtins = document.getElementById("txtins");
         _txtinsamount = document.getElementById("txtinsamount");

           if (_txtinsamount.value !='')
           {
             temp = parseFloat(_txtamount.value) / parseFloat(_txtinsamount.value);
           }
           else
           {
            temp = 0
           }               
           _txtins.value = temp;         
   }



</script>

<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="myform" runat="server" name="myform">
    <div>
        <asp:TextBox ID="txtamount" runat="server" ></asp:TextBox>
        <asp:TextBox ID="txtinsamount" runat="server" onblur="test();"></asp:TextBox>
        <asp:TextBox ID="txtins" runat="server"></asp:TextBox></div>
    </form>
</body>
</html>

2 个答案:

答案 0 :(得分:3)

您的<script>代码需要包含在<head>元素或<body>元素中;它不能只是<html>的直接孩子。

[edit]更重要的是你的“类型”值,正如这里提到的另一个答案。

答案 1 :(得分:3)

您使用text/jscript作为<script>类型。请改用text/javascript

<script type ="text/javascript">

JScript是微软自己的ECMAScript版本 - 难怪它适用于IE。