本文主要是介绍通过select改变其他元素的属性或子节点,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
时间有限,先发源码,以后再整理:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<script language="javascript">
function getOptionTableEdition(){
var tableE = document.getElementById("table");
var mySelect = document.getElementById("select")
if (mySelect.options[0].selected){
while(tableE.childNodes.length >0){
tableE.removeChild(tableE.childNodes[0]);
}
var txt =document.createTextNode(mySelect.options[0].value);
tableE.appendChild(txt);
}else if( mySelect.options[1].selected){
while(tableE.childNodes.length >0){
tableE.removeChild(tableE.childNodes[0]);
}
var txt =document.createTextNode(mySelect.options[1].value);
tableE.appendChild(txt);
}
}
function getOptionTextEdition(){
var TextE = document.getElementById("textfield");
var mySelect = document.getElementById("select")
if (mySelect.options[0].selected){
TextE.setAttribute("value",mySelect.options[0].value);
}else if( mySelect.options[1].selected){
TextE.setAttribute("value",mySelect.options[1].value);
}
}
function getOptionHiddenEdition(){//待测试
var Hidden = document.getElementById("hiddenField");
var mySelect = document.getElementById("select")
if (mySelect.options[0].selected){
Hidden.setAttribute("value",mySelect.options[0].value);
}else if( mySelect.options[1].selected){
Hidden.setAttribute("value",mySelect.options[1].value);
}
}
function getOptionTextAreaEdition(){
var textarea = document.getElementById("textarea");
var mySelect = document.getElementById("select")
if (mySelect.options[0].selected){
while(textarea.childNodes.length >0){
textarea.removeChild(tableE.childNodes[0]);
}
var txt =document.createTextNode(mySelect.options[0].value);
textarea.appendChild(txt);
}else if( mySelect.options[1].selected){
while(textarea.childNodes.length >0){
textarea.removeChild(textarea.childNodes[0]);
}
var txt =document.createTextNode(mySelect.options[1].value);
textarea.appendChild(txt);
}
}
</script>
</head>
<body>
<select name="select" id="select" onChange="getOptionHiddenEdition();">
<option value="1">第一个</option>
<option value="2" selected>第二个</option>
</select>
<table width="200" border="1" >
<tr>
<td id="table"> </td>
</tr>
</table>
<p>
<input type="text" id="textfield" >
</p>
<p> </p>
<form name="form1" method="get" action="">
<input name="hidden" type="hidden" id="hiddenField">
<input type="submit" name="Submit" value="提交">
</form>
<p> <textarea id="textarea"></textarea>
</p>
</body>
</html>
这篇关于通过select改变其他元素的属性或子节点的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!