簡體   English   中英

JavaScript無法在IE中使用,但在FF中可以正常工作

[英]Javascript not working in I.E., but works fine in FF

我具有以下javascript函數:

function updatePrintCost()
{
    var qty = parseFloat(document.getElementById('qty').value);
    var pp = parseFloat(document.getElementById('pp').value);

    var finalPrice = qty * pp;

    if (!isNaN(finalPrice))
        fp.value = "$" + finalPrice.toFixed(2);
    else
        fp.value = "Error";
}

以下HTML代碼調用了它:

<table>
    <tr>
        <td style='border:none;'>Quantity:</td>
        <td style='border:none;'><input type='text' id='qty' name='quantity' onChange="updatePrintCost()" style='width:50px;' /></td>
        <td style='border:none;'>Print Price:</td>
        <td style='border:none;'><input type='text' name='printPrice' id='pp' onChange="updatePrintCost()" style='width:50px;' /></td>
        <td style='border:none;'> = </td>
        <td style='border:none;'><input type='finalPrice' id='fp' placeholder='0.00' style='width:75px;' /></td>
    </tr>
</table>

我在其中放置了一些警報測試,並且正在調用該函數,但是在設置fp值時失敗了。

有人可以看到為什么這行不通嗎?

您的fp聲明在哪里? 你需要:

var fp = document.getElementById('fp');

要么:

if (!isNaN(finalPrice)) 
       document.getElementById('fp').value = "$" + finalPrice.toFixed(2); 
else 
       document.getElementById('fp').value = "Error"; 

您還會在finalPrice類型而不是常規類型中使用怪異的html輸入。

如果您想知道為什么它可以在Firefox中運行,請查看此內容 這是一個跨瀏覽器解決方案。 您的操作方式僅在較新的瀏覽器中有效。

沒有回答您的問題,但在我看來<input type='finalPrice' ...>不是您的意思。 您可能是說<input type='text' name='finalPrice' ...> ,對吧?

它不是fp,值。 將其更改為fpvalue它將起作用

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM