我需要使用 java 脚本清除元素的文本装饰属性。
目前我正在将元素的文本装饰属性设置为“line-through”。在某些时候,我需要撤消罢工过程。
如何使用 javascript 重置文本装饰属性?
我需要使用 java 脚本清除元素的文本装饰属性。
目前我正在将元素的文本装饰属性设置为“line-through”。在某些时候,我需要撤消罢工过程。
如何使用 javascript 重置文本装饰属性?
这是一种方法:
HTML
<p id="a">Some text</p>
CSS
p{text-decoration:line-through;}
js
var p = document.getElementById('a')
p.style.textDecoration = 'none';
将 text-decoration 设置为 none 实际上比将 text-decoration 设置为“”要差一些。$("div").css("文本装饰", "")
不同之处在于,通过设置为空字符串,您实际上删除了 js 设置的属性。说,您的元素text-decoration: "underline"
最初具有(在 css 中,在您使用 jQuery 设置值之前)。将其设置为“无”将是错误的。删除该属性会很好。
Javascript:document.getElementById(element_id).style.textDecoration = "none"
jQuery:$('#element_id').css("text-decoration", "none");
将文本装饰设置为无
或者
document.getElementById(divID).style.removeAttribute("textDecoration",false)
你可以从样式中删除 textDecoration (在 IE 中工作)