【问题标题】:javascript is not working in mozilla but working in other browersjavascript 在 mozilla 中不工作,但在其他浏览器中工作
【发布时间】:2010-02-22 17:56:44
【问题描述】:

使用的技术:- Asp.Net 2.0

代码:- 见下文
描述:- 下面给出的 hello 代码在 i.e. 和其他但不能在所有 mozila 版本中正常工作。javascript 很容易划分两个文本框的值。你很容易理解。

<%@ 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>

【问题讨论】:

  • 试试这个。

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


【解决方案1】:

您使用text/jscript 作为&lt;script&gt; 类型。请改用text/javascript

<script type ="text/javascript">

JScript 是微软自己的 ECMAScript 版本——难怪它可以在 IE 上运行。

【讨论】:

    【解决方案2】:

    您的&lt;script&gt; 标签需要包裹在&lt;head&gt; 元素或&lt;body&gt; 元素中;它不能只是&lt;html&gt; 的直接子代。

    [edit]更重要的是您的“类型”值,正如此处的其他答案所提到的那样。

    【讨论】:

    • 确实,任何与规范的偏差都更有可​​能产生意想不到的结果。或者只是失败。
    • 没有骰子。 下的
    • @Ates 是的,你是对的 - 我可以发誓我过去在 &lt;script&gt; 标签 之后 &lt;body&gt; 时遇到过问题,但即使这样也适用我现在在一个测试页面。尽管如此,将脚本悬挂在头部或身体之外还是有点难看,至少。
    • 您可以将脚本标签放在任何地方(不一定符合 XHTML),但您可以做到。事实上,一般来说,如果可能的话,你应该把你的脚本放在更靠近 HTML 底部的位置,见developer.yahoo.com/performance/rules.html
    • 是的,谢谢 - 我知道在 DOM 末尾加载脚本的好处。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多