让innerHTML获取的内容包含input和select(option)的最新值

function refreshData(){
var allInputObject=document.body.getElementsByTagName("input");
for (i = 0; i < allInputObject.length; i++) {
if(allInputObject[i].type=="checkbox") {
if (allInputObject[i].checked )
allInputObject[i].setAttribute("checked","checked");
else
allInputObject[i].removeAttribute("checked");
}else if(allInputObject[i].type=="radio") {
if (allInputObject[i].checked )
allInputObject[i].setAttribute("checked","checked");
else
allInputObject[i].removeAttribute("checked");
}else{
allInputObject[i].setAttribute("value",allInputObject[i].value);
}
};
for (i = 0; i < document.getElementsByTagName("select").length; i++) {
var sl=document.getElementsByTagName("select")[i];
for (j = 0; j < sl.options.length; j++) {
if (sl.options[j].selected)
sl.options[j].setAttribute("selected","selected");
else sl.options[j]=new Option(sl.options[j].text,sl.options[j].value);
};
};
var textareas = document.body.getElementsByTagName("textarea");
for (i = 0; i < textareas.length; i++) {
textareas[i].innerHTML=textareas[i].value;
textareas[i].style.overflow="hidden";
textareas[i].style.backgroundAttachment="fixed";
textareas[i].style.backgroundRepeat="no-repeat";
textareas[i].style.borderStyle="solid";
textareas[i].style.borderColor="#FFFFFF";
textareas[i].style.resize="none";
}
var ths = document.body.getElementsByTagName("th");
for (i = 0; i < ths.length; i++) {
ths[i].style.border="1px solid #000000";
}
var tds = document.body.getElementsByTagName("td");
for (i = 0; i < tds.length; i++) {
tds[i].style.border="1px solid #000000";
}
var h2s = document.body.getElementsByTagName("h2");
for (i = 0; i < h2s.length; i++) {
h2s[i].style.textAlign="center";
}
var h1s = document.body.getElementsByTagName("h1");
for (i = 0; i < h1s.length; i++) {
h1s[i].style.textAlign="center";
}
};
上一篇:c++map的用法


下一篇:java 实现简单的链式栈