Javascript将图标附加到字段
我的页面上有一个id为orit_c_Discentrate的字段,我需要在该字段后面添加一个图像,并使用onlcick调用另一个名为UpdateGroupedPrice的Javascript函数,我写了以下内容:Javascript将图标附加到字段,javascript,html,onload,Javascript,Html,Onload,我的页面上有一个id为orit_c_Discentrate的字段,我需要在该字段后面添加一个图像,并使用onlcick调用另一个名为UpdateGroupedPrice的Javascript函数,我写了以下内容: function AddPercentImage(){ var img = document.createElement('IMG'); img.setAttribute('src', 'Themes/Img/default/icons/recent_order.gif
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)
}
使用这个附件
window.attachEvent("onload",AddPercentImage);
但是,我在控制台中遇到以下错误
SCRIPT65535:对方法或属性访问的意外调用
要素:
<input name="orit_c_discountrate" class="EDIT" id="orit_c_discountrate" type="text" size="4" maxLength="4"/>
谁能告诉我我做错了什么
谢谢您不能将图像附加为
输入的子元素
。。。您可以将输入包装在
(或另一个元素,如div
)中,并将图像附加到该元素中。。例如:
HTML:
<span><input name="orit_c_discountrate" class="EDIT" id="orit_c_discountrate" type="text" size="4" maxLength="4"/></span>
您不能将图像附加为
输入的子元素。。。您可以将输入包装在
(或另一个元素,如div
)中,并将图像附加到该元素中。。例如:
HTML:
<span><input name="orit_c_discountrate" class="EDIT" id="orit_c_discountrate" type="text" size="4" maxLength="4"/></span>
哪行代码导致此错误?对不起,我的错,appendChild在此处出错>您不能将子项追加到输入中…哦,好的,那么我的选项是什么?哪行代码导致此错误?对不起,我的错,appendChild在此处出错>您不能将子项追加到输入中…哦,好的,那么我的选项是什么?