Javascript自动计算获胜';t在FF中运行,在IE和Chrome中运行良好
我在标记中定义了以下asp.net文本框:Javascript自动计算获胜';t在FF中运行,在IE和Chrome中运行良好,javascript,asp.net,firefox,Javascript,Asp.net,Firefox,我在标记中定义了以下asp.net文本框: <div class="OptionSelect2"> <asp:TextBox ID="txtCalculateWeightRollSize" CssClass="_100" runat="server"></asp:TextBox> </div> Javascript(重新格式化为更容易适应问题格式)如下所示: function RollBWghtPCutoffNWebsCalcs() {
<div class="OptionSelect2">
<asp:TextBox ID="txtCalculateWeightRollSize" CssClass="_100" runat="server"></asp:TextBox>
</div>
Javascript(重新格式化为更容易适应问题格式)如下所示:
function RollBWghtPCutoffNWebsCalcs() { ZeroPctLbs(); }
function ZeroPctLbs() {
//Get the values
var rollSize = document.getElementById("<% =txtCalculateWeightRollSize.ClientID %>").value.replace("$", "").replace("%", "");
//Get other controls' values
//Make them numbers, if necessary
rollSize = +rollSize;
//convert other controls
//Calculate and assign the result
var result = //math;
document.getElementById("<% =lblCalculateWeightZeroPercentLbsValue.ClientID %>").innerText = result;
}
函数RollBWghtPCutoffNWebsCalcs(){ZeroPctLbs();}
函数ZeroPctLbs(){
//获取值
var rollSize=document.getElementById(“”).value.replace(“$”,“”)。replace(“%”,“”);
//获取其他控件的值
//如果有必要,给他们打电话
rollSize=+rollSize;
//转换其他控件
//计算并分配结果
var result=//数学;
document.getElementById(“”).innerText=result;
}
这在IE和Chrome中都可以正常工作。然而,在Firefox中,它失败了。在firebug(我今天才使用)中,onblur事件似乎会触发,但在代码中,当它应该调用RollBWghtPCutoffNWebsCalcs()时,它会传递它,就好像调用不存在一样。如果我将断点直接放在任何Javascript函数中,它永远不会被触发
文本框在HTML中显示为正确呈现:
<input name="ctl00$MainContent$txtCalculateWeightRollSize" type="text" id="MainContent_txtCalculateWeightRollSize" class="_100" onblur="Javascript:RollBWghtPCutoffNWebsCalcs();" />
我认为这说明了问题所在。onblur在任何浏览器中都不起作用,但这与我过去处理Firefox问题的经验是一致的。当直接呈现时,它确实在Chrome和IE中工作,JSHint表明Javascript是有效的
我怀疑我正在做的事情并不完全符合标准,因为Firefox(据我所知)几乎是一种基于标准的web体验。为什么它不跑?求你了。有时候事情很简单 .innerText不受FireFox支持。改用innerHTML 一旦我停止使用Firebug并切换到FF的内置调试器,我就能够真正跟踪我的代码——我想我只是不知道如何使用Firebug。让我感到奇怪的是,FF将使用innerText从标签中获取值,并以这样一种方式写入它们,即后续函数调用可以读取写入的值,但它不会呈现innerText tldr强> 使用innerHTML处理Javascript中的标签文本
<input name="ctl00$MainContent$txtCalculateWeightRollSize" type="text" id="MainContent_txtCalculateWeightRollSize" class="_100" onblur="Javascript:RollBWghtPCutoffNWebsCalcs();" />