关于一js的实现.
一页面:
在页面左侧有: "你好 "的文本和 "确定 "的按扭.我点击按扭后,在页面右侧显示 "你好 "的文本,同时还有text文本.当我再点左侧 "确定 "按扭的时候,右面的相关显示清空.
------解决方案-------------------- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 " />
<title> 无标题文档 </title>
<style type= "text/css ">
#div1{ float:left}
#div2{width:200px; height:100px; line-height:100px; text-align:center; background:#eee; float:left}
</style>
</head>
<body>
<div id= "div1 ">
<input type= "text " id = "text1 "/>
<input type= "button " value= "click me " onclick= "modity(); " />
</div>
<div id= "div2 "> </div>
</body>
</html>
<script type= "text/javascript ">
function modity()
{
if(document.getElementById( "div2 ").innerHTML != " ")
{
document.getElementById( "div2 ").innerHTML = " ";
}
else
{
document.getElementById( "div2 ").innerHTML = "你好! " + document.getElementById( "text1 ").value;
}
}
</script>
---
这样的行不?
------解决方案-------------------- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 " />
<title> 无标题文档 </title>
<style type= "text/css ">
#div1{float:left}
#div2{width:200px; height:100px; line-height:100px; text-align:center; background:#eee; float:left}
</style>
</head>
<body>
<div id= "div1 ">
<input type= "text " id = "text1 " onKeyUp= "change(); "/>
<input type= "button " value= "click me " onclick= "modity(); " />
</div>
<div id= "div2 "> </div>
</body>
</html>
<script type= "text/javascript ">
function modity()
{
document.getElementById( "div2 ").innerHTML = " ";
}
function change()
{
document.getElementById( "div2 ").innerHTML = "你好! " + document.getElementById( "text1 ").value;
}
</script>
------解决方案-------------------- <body>
<script language= "javascript ">
function doIt(obj){
var oCon = document.getElementById( "conDiv ");
if(obj.clonedObj == null){
var oNewCode = obj.cloneNode(true);
obj.clonedObj = oNewCode;
oCon.insertAdjacentElement( "beforeEnd ", oNewCode);
} else {
var oNewCode = obj.clonedObj;
oNewCode.removeNode(true);
obj.clonedObj = null;
}
}