Java脚本在某些浏览器中不起作用 [英] java script not working in some browsers

查看:64
本文介绍了Java脚本在某些浏览器中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我有这样的脚本:
崩溃

Hi All,
I have script like this:
Collapse

<script type="text/javascript">
        function count(txt)
       {
          var textchar='<%= TextBox2.MaxLength %>';
          var textbox=document.getElementById(txt);
          var lbl=document.getElementById('<%= Counlbl.ClientID %>');
          if(textbox.value.length>textchar)
          {
          textbox.value=textbox.value.substrung(0,textchar);
          }
          lbl.innerText=textchar-textbox.value.length+" Characters remaining..";
       }
   </script>


此脚本可以在Internet Explorer中工作,但不能在Mozilla Firefox中工作,我还把最大长度设置为120个字符,超过长度后会引发异常

1.如何防止此异常
2.如何使此脚本在Firefox中运行.

谁能帮我.

在此先感谢


This script working in internet explore but not working in Mozilla Firefox and also i put max length as 120 characters it raises exception after crossing length

1.How can i prevent this exception
2.How can i make this script to work in Firefox.

Can any one please help me.

Thanks in Advance

推荐答案

需要更改以下几项:

1."substrung"应为"substring"

2.也可以使用"innerHTML"而不是"innerText"在Firefox中运行.

您没有说明异常是什么,所以这可能无法解决您的实际问题.
There are a couple of things to change:

1. "substrung" should be "substring"

2. use "innerHTML" instead of "innerText" to work in Firefox too.

You didn''t say what the exception is, so this might not solve your actual problem.


问题1:您可以使用try ... catch ...来防止异常
http://www.w3schools.com/js/js_try_catch.asp [ http://www.google.com/search?q=javascript+exception+handling [ ^ ]

问题2:您可以在脚本中使用jquery lib.这是一个出色的js库和交叉浏览器.
http://jquery.com/ [ ^ ]
question 1: you can use try...catch... to prevent the exception
http://www.w3schools.com/js/js_try_catch.asp[^]

you also can seek redress at google
http://www.google.com/search?q=javascript+exception+handling[^]

question 2: you can use jquery lib in you script. It''s an excellent js lib and cross brower.
http://jquery.com/[^]


这篇关于Java脚本在某些浏览器中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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