如何用js控制margin-bottom属性

 时间:2024-10-12 17:53:36

1、新建一个html文件,命名为test.html,用于讲解如何用js控制margin-bottom属性。

如何用js控制margin-bottom属性

2、在test.html文件内,使用p标签创建两行文字,并设置第一行文字的p标签id为one。

如何用js控制margin-bottom属性

3、在test.html文件内,使用button标签创建一个按钮,按钮名称为“控制margin属性”。

如何用js控制margin-bottom属性

4、在test.html文件内,给button按钮绑定onclick点击事件,当按钮被点击时,执行myfun()函数。

如何用js控制margin-bottom属性

5、在test.html文件内,在js标签内,创建myfun()函数,在函数内,使用getElementById()方法通过id获得第一个p标签对象。

如何用js控制margin-bottom属性

6、在myfun()函数内,再通过给style中marginBottom属性赋值的方式,控制margin-bottom的样式,例如,这里设置为80px。

如何用js控制margin-bottom属性

7、在浏览器打开test.html文件,点击按钮,查看实现的效果。

如何用js控制margin-bottom属性如何用js控制margin-bottom属性
  • 如何做一个开机后台运行的CMD
  • Linux中如何下载安装老版本的谷歌浏览器
  • 怎样在WinPE下安装XP系统
  • jqgrid如何动态设置列的显示和隐藏
  • 使用dos窗口查看oracle的DDL语句
  • 热门搜索
    怎么样练腹肌 怀孕一个月怎么避孕 qq邮箱怎么发送文件夹 宝宝感冒发烧怎么办 笔记本电脑开机黑屏怎么办 牛肉饺子馅怎么调 怎么才能不怀孕 竹笋怎么保存 投影手机怎么样 怎么修改无线密码