휄로우,
웹 페이지의 현재 상태를 저장하는 코드를 작성했습니다. 입력으로 값을 변경하는 텍스트 상자가있을 경우 변경 사항은 html 코드에 등록되지 않습니다. 내가 전화했을 때 :js-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:<br><textarea rows="20" cols="60">'+html+'</textarea><br><input type=button value=close onclick=removeParent(this)>';
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:<br><textarea id=code rows="20" cols="60"></textarea><br><input type=button value=cancel onclick=removeParent(this)> <input type=button value=load onclick=document.getElementsByTagName(\'body\')[0].innerHTML=decodeURI(get(\'code\').value)>';
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);
}
왜'setAttribute'가 작동하고'o.value = ... '가 아닌지 당신의 질문입니까? – geowa4