2016-12-24 83 views
2

我有以下脚本,根据用户输入单选按钮计算价格并将其输出到html部分。该脚本不能正常工作在Internet Explorer中。它适用于FF,Chrome等。脚本应该从单选按钮获取输入,然后根据输入输出不同的价格。它不会在IE中输出价格。在IE中不工作的脚本

var newprice = "";   

function CalcPrice(){ 
    // I take the input from the radio buttons here 
    var goals = $("#menu input[type='radio']:checked").val(); 

    if (goals=="Weight Loss"){ 
     newprice="45"; 
    } else { 
     newprice="55"; 
    } 

    $('.pricetotal').html("$"+newprice.toFixed(2)); 
} 

HTML

<form class= "meal-table" id="meal-radio" onsubmit="return false"> 
      <fieldset id="menu"> 
     <input type="radio" id="radio01" name="menu" value="Weight Loss" /> 
     <input type="radio" id="radio02" name="menu" value= "Performance"/> 
      </fieldset> 
    <div> 
     <div class="meal-plan-btn"> 
     <button id="mealbtn" onclick="CalcPrice()">Add To Cart</button> 
    </div> 
</div> 
</form> 

//这是那里的价格将被注入

  <div class="pricebox" id="priceboxmobile"> 
      <div class="pricetotal" > 
       <span ></span> 
      </div></div> 
+0

检查这个http://stackoverflow.com/questions/412734/jquery-html-attribute-not-working-in-ie – Deep

+0

命中F12打开开发人员工具。转到“控制台”选项卡。有脚本错误吗?哪个IE版本? – EricLaw

+0

正如@EricLaw上文所述,请说明您使用的IE版本。一些旧版本可能不支持一些常见的JavaScript。 – TrojanByAccident

回答

0

更改此行

$('.pricetotal').html("$"+newprice.toFixed(2)); 

要:

$('.pricetotal').empty().html("$"+newprice.toFixed(2)); 

似乎工作,任何人都知道为什么?

+0

我无法接受我自己的答案,但这是答案 –

1

我认为,如果你改变

$('.pricetotal').html("$"+newprice.toFixed(2)); 

$('.pricetotal span').html("$"+newprice.toFixed(2)); 

它将被固定。

IE对于那些事情来说是一个坚持者。
但在这种情况下,它是你想要的,否则你的span将被删除。
另外,除去span共..