DOM访问和处理HTML文档的标准方法

innerHTML获取或替换HTML元素的内容

<p id="d">对于错我无法来判断 </p>
<script type="text/javascript">
var myCom = document.getElementById("d");
document.write("p的标签原始内容"+ myCom.innerHTML+"<br>");//读取当前元素
myCom.innerHTML="史莱姆";
document.write("p的标签修改内容"+ myCom.innerHTML+"<br>");//修改元素

</script>

显示与隐藏

<div id="cons">
开始,我来说!结束,谁来说?

</div>
<form>
<input type="button" value="显示" οnclick="Dlasy()" >
<input type="button" value="隐藏" οnclick="hide()">
</form>

<script>
var mybs =document.getElementById("cons");
function Dlasy(){
mybs.style.display="block";

}
function hide(){
mybs.style.display="none";
}

</script>


<style>

.first{
overflow: hidden;
}
.second{
color:#f00;
}
.third{
width:100px;
height:60px;
color: #880e74;
}

.fourth{
display: none;
}
.fifth{
color:#00ff00;
display: block;
}
.sixth{

}



</style>

<p id="com" class="first" >该向前看,不应该停留在原地。</p>
<form>
<input type="button" value="改变颜色" οnclick="gbcolor()">
<input type="button" value="改变宽高" οnclick="gaodu()">
<input type="button" value="隐藏内容" οnclick="yinan()">
<input type="button" value="显示内容" οnclick="xianshi()">
<input type="button" value="取消设置" οnclick="cancelsz()">

</form>
<script>
var mycom1 = document.getElementById("com");

document.write(mycom1.innerHTML);
function gbcolor(){
mycom1.className="second";

}
function gaodu(){
mycom1.className="third";
}
function yinan(){
mycom1.className="fourth";
}
function xianshi(){
mycom1.className="fifth";
}
function cancelsz(){
mycom1.className="sixth"
/* mycom1.style.cssText="";*/
}
</script>

 

 

 

 
 
 

转载于:https://www.cnblogs.com/zhanghongjuan/p/9923094.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值