首页 > Web开发 > 详细

二、innerHTML应用测试

时间:2016-12-23 22:09:24      阅读:151      评论:0      收藏:0      [点我收藏+]

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>innerHTML测试页面</title>

<script>


function Test(){
var str="";
str+="Hello,";
str+="This is a Test!<br />";
str+="I Love you;<br />";
str+="I Love you,too!";
p.innerHTML=str+"<br /><br />"+Math.random();
setTimeout(‘Test();‘,1000);
}
function chageDiv(number)
{
if (number == 1) {
document.getElementById("div").innerHTML = "值为1";
}
if (number == 2) {
document.getElementById("div").innerHTML = "值为2";
}
}
function chageA(number)
{
if (number == 1) {
document.getElementById("A").innerHTML = "值为1";
}
if (number == 2) {
document.getElementById("A").innerHTML = "值为2";
}
}
</script>

 

</head>
<body onload="Test()">

<span id="p"></span><br><br>

innerHTML传值测试(DIV块):<br><br>
<div id="div" style="width: 180px;height:120px;color: red ;font-size: 30px;background: green"> DIV块 </div>
<a href="#" onClick="chageDiv(1)">改变值为1</a>
<a href="#" onClick="chageDiv(2)">改变值为2</a><br><br>

innerHTML传值测试(a标签):<a id="A" style="font-size: 38px;color: red"> a标签</a><br>
<a href="#" onClick="chageA(1)">改变值为1</a>
<a href="#" onClick="chageA(2)">改变值为2</a>

<script type="text/javascript">
function chageSpan(number)
{
if (number == 1) {
document.getElementById("span1").innerHTML = "值为1";
}
if (number == 2) {
document.getElementById("span1").innerHTML = "值为2";
}
}
</script>
<br><br>
<div>
Span行测试:

<span id="span1" style="font-size: 30px;color: red">默认值</span><br>
<a href="#" onClick="chageSpan(1)">改变值为1</a>
<a href="#" onClick="chageSpan(2)">改变值为2</a>

</div>

二、innerHTML应用测试

原文:http://www.cnblogs.com/frankchia/p/6216086.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!