研究员,结果
我写了一些代码来保存网页的当前状态。如果有一个文本框,我通过输入更改了值,则更改未在html代码中注册。即使我打电话:
object.value = 'x';是不会改变价值。我用的时候:
object.setAttribute('value','x');然后更改在html代码中注册。
有一个循环遍历文本框设置onchange属性不是一个解决方案因为我有特殊的文本框已经有他们的onchange属性设置。
谢谢你的帮助
function SaveHTML()
{
removeThis(get('Source'));
var newdiv = document.createElement('div');
newdiv.setAttribute('id','Source');
newdiv.style.position= 'absolute';
newdiv.style.top= (tempY-200)+'px';
newdiv.style.left= (tempX+30)+'px';
newdiv.style.backgroundColor = 'white';
var html=encodeURI(document.getElementsByTagName('body')[0].innerHTML);
newdiv.innerHTML='HTML:'+html+'';
document.body.appendChild(newdiv);
}
function LoadHTML()
{
removeThis(get('Source'));
var newdiv = document.createElement('div');
newdiv.setAttribute('id','Source');
newdiv.style.position= 'absolute';
newdiv.style.top= (tempY-200)+'px';
newdiv.style.left= (tempX+30)+'px';
newdiv.style.backgroundColor = 'white';
newdiv.innerHTML='HTML:';
document.body.appendChild(newdiv);
}
function get(Element)
{
return document.getElementById(Element);
}
function removeThis(obj)
{
try{
obj.parentNode.removeChild(obj);
}
catch (e) {
return;
}
}
function removeParent(obj)
{
obj.parentNode.parentNode.removeChild(obj.parentNode);
}