使用setAttribute()修改display属性的坑
来源:互联网 发布:网络改造设备 编辑:程序博客网 时间:2024/06/05 14:46
今天在慕课网学习的时候遇到一个问题。
有这样一个盒子:
<html><head><style>#login_box{width:300px;height:150px;background:#eee;position:absolute;left:50%;top:50%;margin-left:-150px;margin-top:-75px;display:none;}</style></head><body><div id="login_box"><p>用户登录</p></div></body></html>
根据任务要求,我需要让这个盒子显示在屏幕上。
但是以下代码没有效果:
<script>var box = getElementById("login_box");box.setAttribute("display","block");</script>
也就是说,“display”不是一个HTML属性,是一个CSS属性,如果要用setAttribute方法修改的话,代码如下:
box.setAttribute("style","display:block");
但是不建议采用这种方法。
推荐使用:
box.style.display = "block";
阅读全文
2 0
- 使用setAttribute()修改display属性的坑
- css display属性的使用
- 使用.添加属性和使用setattribute的区别
- 使用setAttribute()改变网页中标签的onclick属性
- IE中使用setAttribute方法设置属性的问题
- 不使用setAttribute()方法改变某个图片的src属性
- jquery修改display属性
- getAttribute/setAttribute的使用
- fullcalendar 属性修改General Display
- js的setAttribute的使用
- javascript中setAttribute的使用
- JS中setAttribute的使用
- 设置元素的属性attr 和setAttribute
- jdom中使用setAttribute(Attribute attribute)方法设置属性的注意事项
- JS getAttribute和setAttribute(取得和设置属性)的使用介绍
- display属性的应用
- css的display属性
- display的属性值
- 操作系统简介
- Invalidate和UpdateWindow的区别
- 函数的图像怎么样画
- 巴别鸟App产品体验报告
- Androiid 如何动态加载assets目录下的xml布局文件(包括Drawable xml)
- 使用setAttribute()修改display属性的坑
- public class与public partial class
- Android Studio项目提交GitHub时的出错处理
- 数据结构是哈希表(hashTable)
- AngularJs 解决不能设置Content-Type的方法
- 与Kotlin的第一次接触(Kotlin一)
- <基础原理进阶>机器学习算法python实现【2】--ForwardPass&BackPropagation
- QWidget嵌入QML窗口中
- 算法之插入排序