每个输入都有2个输入和图像。当我 单击输入中的图像我只想在此输入中清除文本。 怎么做到这个?
这是我的功能
function deleteText (id)
{
//here i should get txtNameFirm ot txtNameOwner
var element = document.getElementsById(id);
element.value=" ";
}
HTML
<div class="outer" >
<input type="text" id = "txtNameOwner" value="ENTER NAME OF OWNER" />
<img src="file:///C:/Users/gismo2/Dropbox/GISmoBusinessCatalogProject-Feb2013/IconResources/close_btn.png" onclick="deleteText('txtNameOwner')/>
</div>
<div class="outer" >
<input type="text" id = "txtNameFirm" value="ENTER NAME OF FIRM" />
<img src="file:///C:/Users/gismo2/Dropbox/GISmoBusinessCatalogProject-Feb2013/IconResources/close_btn.png" onclick="deleteText('txtNameFirm')" />
</div>
答案 0 :(得分:1)
试试这个
var element = document.getElementById(id);
element.value='';
你写了getElementsById
getElementById
应该工作。