我是新來的JavaScript,並作爲大學裏的項目的一部分,我需要包括一些。我創建了一個簡單的.js文件並將其鏈接到使用<script src="main.js"></script>
遺漏的類型錯誤:字符串不是一個函數
我創建了一個名爲sellYourHome.html
另一頁,並增加了<section>
標籤有一張桌子和創建了一個簡單的表格,計算comission,並將結果顯示回我的index.html文件在輸入字段中。
function comCalc()
{
prcHouse = parseFloat(document.getElementById('prcHouse').value);
commision = 0.25;
result = prcHouse * commision;
document.getElementById('prcHouse').value = result.toString();
}
工作。
現在在這個函數下,我想創建另一個元素,它拾取一個<div>
元素並將background-color
更改爲藍色。
所以我創建了一個index.html
形式和以同樣的方式連接的同一個.js文件給它。
這是我的HTML:
<div id="mainContent">
<p>hello</p>
<form id="bgColor">
<table>
<tr>
<td>
<input type="button" value="blue" onclick="bgColor('blue');">
</td>
</tr>
</table>
</form><!-- end of bgColor Form-->
</div>
我的JavaScript像這樣:
function comCalc()
{
prcHouse = parseFloat(document.getElementById('prcHouse').value);
commision = 0.25;
result = prcHouse * commision;
document.getElementById('prcHouse').value = result.toString();
}
function bgColor(color)
{
var div = document.getElementById('mainContent');
div.style.background=color;
}
當我運行它,我得到的控制檯上的錯誤:
Uncaught TypeError: String is not a function
我我在一個叫SWRIron瀏覽器中運行的(這是基於瀏覽器和HTML5是-complient)。
我在做什麼錯?
我不會在任何地方看到任何'sting' – Brian
我的朋友在兩個實例中輸入錯字=「String」 – StudentwebCoding