html代码_html/css_WEB-ITnose
程序员文章站
2022-05-06 18:12:50
...
document.getElementById('div1').innerHTML=document.getElementById('div1').innerHTML.replace("Dear ","Dear "+document.getElementById('rName0').value);
这句代码在IE8,IE9会出错 (error:该操作的目标元件无效)
求解决方案
回复讨论(解决方案)
放到window.onload事件中
window.onload = function () { document.getElementById('div1').innerHTML=document.getElementById('div1').innerHTML.replace("Dear ","Dear "+document.getElementById('rName0').value);}
在部分浏览器下 innerHTML 属性为只读的 不支持写入
解决方案?换jquery
可以换成jQuery:
test
放到window.onload事件中
window.onload = function () { document.getElementById('div1').innerHTML=document.getElementById('div1').innerHTML.replace("Dear ","Dear "+document.getElementById('rName0').value);}
一开始就报错了
放到window.onload事件中
window.onload = function () { document.getElementById('div1').innerHTML=document.getElementById('div1').innerHTML.replace("Dear ","Dear "+document.getElementById('rName0').value);}
一开始就报错了
发下完整代码看看
换jq吧。。。。innerHTML 有支持缺陷哟。。。
function showPreview() { var passcode=document.getElementById("passcode"); if(passcode.value!='') { if(checkDataBase()==true) { var seltitle=document.getElementById("cl_lang"); var title=document.getElementById("hiduselanguage"); var tablemain=document.getElementById("tablemain"); var table_=document.getElementById("table_"); var sCOName=document.getElementById("sCOName"); var boothNumber=document.getElementById("boothNumber"); var sName=document.getElementById("sName"); var sEmail=document.getElementById("rEmail0"); var message=document.getElementById("message"); var hall=document.getElementById("hall"); var phone=document.getElementById("phone"); var website=document.getElementById("website"); var fEmail=document.getElementById('sEmail') if(seltitle.options[seltitle.selectedIndex].value == "") { var labfrom=document.getElementById("labfrom"); var labto=document.getElementById("labto"); var labattn=document.getElementById("labattn"); var labemail=document.getElementById("labemail"); var labfemail=document.getElementById("labfemail"); var labbooth=document.getElementById("labbooth"); var labcontact=document.getElementById("labcontact"); var labhall=document.getElementById("labhall"); var labphone=document.getElementById("labphone"); var labwebsite=document.getElementById("labwebsite"); var labmessage=document.getElementById("labmessage"); for(i=0;i 0) { labwebsite.href=website.value; } if (labmessage) { labmessage.value=message.value; } setHTMLToObjectsByName("labfrom", sCOName.value); setHTMLToObjectsByName("labemail", sEmail.value); setHTMLToObjectsByName("labfemail", fEmail.value); setHTMLToObjectsByName("labbooth", boothNumber.value); setHTMLToObjectsByName("labcontact", sName.value); if (hall) { setHTMLToObjectsByName("labhall", hall.value); } if (phone) { setHTMLToObjectsByName("labphone", phone.value); } if (website && website.value.length > 0) { setHREFToObjectsByName("labwebsite", website.value); } if (message) { setValueToObjectsByName("labmessage", message.value); } document.getElementById('div1').innerHTML=document.getElementById('div1').innerHTML.replace("Dear ","Dear "+document.getElementById('rName0').value);} tablemain.style.display='none'; table_.style.display='none'; } } } else { alert(''); passcode.focus(); } }
后来在function 删掉那句,添加下面
window.onload = function () { document.getElementById('div1').innerHTML=document.getElementById('div1').innerHTML.replace("Dear ","Dear "+document.getElementById('rName0').value);}
目前已换成jquery,可以用