javascript属性在FF中不起作用 [英] javascript attribute not working in FF

查看:74
本文介绍了javascript属性在FF中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我为CS中的按钮分配了一些属性,并尝试通过
之类的javascript在aspx页面上获取该属性

Hi,

I am assigning some attribute to button in CS and try to get that on aspx page through javascript like

var MaxEmptyChambers = document.getElementById(btnClientId).MaxEC;



但这并没有返回FF中的MaxEC值.在IE中运行正常.

有任何建议.



But this is not returning that MaxEC value in FF. It is working fine in IE.

Any suggestion.

推荐答案

它有效,我试过了.这是一个错误:btnClientId必须用引号引起来.不要忘记属性id本身.



我上面提到的问题是真正的问题.我确认这很重要-它不适用于FireFox.您确定它可以在IE中正常工作吗?什么版本.
刚开始,我看不到MaxEC的问题(并且昨天未能测试,但显然不能正常工作).应该将其更改为Manfred建议的代码.我也测试过了.

SA
It works, I tried. Here is a bug: btnClientId must be in quotation marks. Don''t forget the attribute id itself.



The problem I mentioned above is the real problem. I confirm it does matter — it would not work with FireFox. Are you sure it works in IE as is? What version.
At first, I failed to see the problem with MaxEC (and I failed to test it yesterday, but it''s apparent is would not work as well). It should be changed to the code Manfred suggested. I tested it, too.

SA


您的代码无法在FireFox中工作的问题是IE支持读取属性,就像它们是包含DOM元素的属性一样,而FireFox可以支持.使用FireFox,您将必须使用getAttribute:

请在IE和FF中尝试以下代码.您最终将看到差异:

The problem that your code is not working in FireFox is that IE supports reading of attributes as if they were properties of the containing DOM element whereas FireFox does NOT support this. Using FireFox you will have to use getAttribute:

Please try the following code in both IE and FF. You will ultimately see the difference:

<html>
<head>
    <script type="text/javascript">
        function show(eleID)
        {
            alert("1. Fetching element with id = " + eleID);
            var element = document.getElementById(eleID);
            alert("2. Element: " + element);
            var attribute = element.getAttribute("MaxEC");
            alert("3. Attribute: " + attribute);

            var IEAttribute = element.MaxEC;
            alert("4. IE Style: " + IEAttribute);
        }
    </script>
</head>
<body onload="show('btnClientId');">
<h1>Get attribute test!</h1>
<input id="btnClientId" type="button" value="Hello!" name="Whatchamacallit" MaxEC="This is the value of attribute MaxEC"/>
</body>
</html>




希望这可以为您解决问题!

最好的问候,

-MRB




Hope this clears the issue for you!

Best Regards,

-MRB


我找不到关于MaxEC属性的任何引用.因此,我得出的结论是,您正在使用某种带有专有接口(方法和属性)的ActiveX组件. FF不支持现成的ActiveX,但是如果您想在FF上使用ActiveX,则可能需要访问以下页面: ^ ].

同样以变量btnClientId的名称命名,我认为您的代码片段最可能应如下所示:

I couldn''t find any reference to a property MaxEC as far and wide I have looked. Thus I came to the conclusion that you are using some sort of ActiveX component with a proprietary interface (methods and properties). FF doesn''t support ActiveX out of the box, but there is a page you may want to visit if you want to use ActiveX on FF: http://support.mozilla.com/en-US/kb/ActiveX[^].

Also going by the name of the variable btnClientId I think your code snippet should most probably read like this:

var MaxEmptyChambers = document.getElementById("<%= btnClientId %>").MaxEC;



最好的问候,

-MRB



Best Regards,

-MRB


这篇关于javascript属性在FF中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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