jQuery 获取元素margin-bottom值

博客可能围绕jQuery以及margin-bottom、marginBottom展开,jQuery是前端开发常用库,margin相关属性用于页面布局样式设置,在前端页面设计中有重要作用。

var px = $('#sampleDiv').css('marginBottom');  // px = '400px'

var num= parseInt( $('#sampleDiv').css('marginBottom') );  // num = 400

 

第1关:jQuery获取内容和属性编程要求 根据提示,在右侧编辑器Begin至End之间填充代码,获取元素的内容和属性。要求如下: 点击【获取文本内容】按钮,直接弹出类名为box的元素的文本内容; 点击【获取内容】按钮,直接弹出类名为box的元素的内容; 点击【获取表单 value 】按钮,获取类名为getVal的元素的value和type属性,用"---"拼接,并赋给变量getValue,弹出变量getValue的。 格式注意: 获取元素统一用类名获取; 统一用双引号""表示字符串。<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script> <style> .container{ width: 300px; margin: 30px auto; } .box{ border: 2px solid #000; background: #eee; padding: 10px; } p{ font-size: 18px; } input{ height: 30px; } button{ margin-bottom: 30px; } </style> </head> <body> <div class="container"> <button class="btn1">获取文本内容</button> <button class="btn2">获取内容</button> <button class="btn3">获取表单value</button> <div class="box"> <p>我是第一行</p> <p>我是第二行</p> 输入框:<input class="getVal" type="text" value="Hello Educoder"/> </div> </div> <script> $(function(){ //------------ Begin ----------- alert(textContent); alert($(".box").html()); alert(getValue)$(".btn3").click(function(){ var value = $(".getVal").val(); var type = $(".getVal").attr("type"); var getValue = value + "---" + type; alert(getValue); }); //------------ End -------------- }) </script> </body> </html>
03-09
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

_格鲁特宝宝

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值