日期:2014-05-16 浏览次数:20415 次
<input id="Text1" name="txt1" type="text" onblur="return text_onblur"/> <img id="img1" alt="" src="3869245_175711061690_2.jpg" style="width: 22px; height: 20px" /> <input id="Text7" readonly="readonly" type="text" value="必须填写" class="txt" /><br />
y = document.getElementById(("Text" + name)); aimg = "img" + name; atext="Text"+(name+6); if (y.value == "") { aimg.src = "禁止.jpg"; aimg.style = "width: 22px; height: 20px"; atext.value = "此项不能为空"; }
楼主可以试试下面的代码: <input id="Text1" name="txt1" type="text" onblur="return onText1_Blur(this);"/> <img id="img1" alt="" style="width: 100px; height: 100px" /> <input id="Text7" readonly="readonly" type="text" value="必须填写" class="txt" /><br /> <script> var img = document.getElementById('img1'); function onText1_Blur(sender,args){ img.src = 'http://avatar.profile.csdn.net/F/A/A/2_w362435819.jpg'; } </script>
------解决方案--------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script> function text_onblur(name) { y = document.getElementById(("Text" + name)); aimg = "img" + name; atext = "Text" + (name + 6); if (y.value == "") { document.getElementById(aimg).src = "禁止.jpg"; document.getElementById(aimg).style = "width: 22px; height: 20px"; document.getElementById(atext).value = "此项不能为空"; } } </script> </head> <body> <input id="Text1" name="txt1" type="text" onblur="text_onblur(1)"/> <img id="img1" alt="" src="3869245_175711061690_2.jpg" style="width: 22px; height: 20px" /> <input id="Text7" readonly="readonly" type="text" value="必须填写" class="txt" /><br /> </body> </html>