Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/402.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript将图标附加到字段_Javascript_Html_Onload - Fatal编程技术网

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

我的页面上有一个id为orit_c_Discentrate的字段,我需要在该字段后面添加一个图像,并使用onlcick调用另一个名为UpdateGroupedPrice的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)
}
使用这个附件

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在此处出错>您不能将子项追加到输入中…哦,好的,那么我的选项是什么?