我有我的頁面上的字段orit_c_discountrate的ID我需要一個onlcick調用另一個JavaScript函數命名UpdateQuotedPrice我有這個下面寫了這個領域後,添加圖像:的Javascript追加圖標到現場
function AddPercentImage(){
var img = document.createElement('IMG');
img.setAttribute('src', 'Themes/Img/default/icons/recent_order.gif');
img.onclick = function(){
UpdateQuotedPrice();
}
//This is the line that errors
document.getElementById('orit_c_discountrate').appendChild(img)
}
並使用此的attachEvent
window.attachEvent("onload",AddPercentImage);
但我得到以下錯誤控制檯
SCRIPT65535:意外調用方法或屬性訪問。
元素:
<input name="orit_c_discountrate" class="EDIT" id="orit_c_discountrate" type="text" size="4" maxLength="4"/>
誰能告訴我什麼,我做錯了什麼?
感謝
哪行代碼導致此錯誤? – ManseUK 2012-03-05 16:57:58
抱歉,我的壞,appendChild錯誤 – 2012-03-05 17:02:27
Works here> http://jsfiddle.net/eNnWv/ < - 沒有問題(除了圖像不存在!!)...你確定你有一個ID與一個元素'orit_c_discountrate'。你能包含你的HTML嗎? – ManseUK 2012-03-05 17:05:59