简体   繁体   English

Javascript从样式中删除特定属性

[英]Javascript Remove specific attribute from style

Hello i have started to learn Javascript and i was wondering if there is a way to remove a specific attribute from the style here is an example that explain what i mean 您好,我已经开始学习Javascript,我想知道是否有一种方法可以从样式中删除特定属性,这里有一个示例说明了我的意思。

  <div id="divbrd" style="width:500px; height:350px; border:1px solid #000; box-shadow:10px 5px 10px #777;"></div>

this is a div tag with a style so if i want to remove the box-shadow from the style attribute how can i do this here is what i have done : 这是具有样式的div标签,因此,如果我想从样式属性中删除框阴影,我该怎么做呢?

<script type="text/javascript">
    var   div_brd = document.getElementById("divbrd");
    div_brd.removeAttribute("style","box-shadow");
    </script>

correct me please ... thanks 请纠正我...谢谢

Try this 尝试这个

<script type="text/javascript">
var   div_brd = document.getElementById("divbrd");
div_brd.style.boxShadow = "none";
</script>

Fiddle: 小提琴:

In this fiddle there is box shadow on div but it's removing from js 在这个小提琴中,div上有盒子阴影,但它正在从js中删除

以防万一,如果您还想学习jQuery。

$('#divbrd').css("box-shadow", "");

this will remove the attribute 这将删除该属性

<script type="text/javascript">
var   div_brd = $("#divbrd");
div_brd.style.boxShadow = "none";
</script>

OR 要么

<script type="text/javascript">
     $('#divbrd').css("box-shadow", "none");
    </script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM