0

我需要使用 java 脚本清除元素的文本装饰属性。

目前我正在将元素的文本装饰属性设置为“line-through”。在某些时候,我需要撤消罢工过程。

如何使用 javascript 重置文本装饰属性?

4

4 回答 4

2

这是一种方法:

HTML

<p id="a">Some text</p>

CSS

p{text-decoration:line-through;}

js

var p = document.getElementById('a')
p.style.textDecoration = 'none';

http://jsfiddle.net/jasongennaro/nVeGB/

于 2011-07-28T12:19:56.457 回答
0

将 text-decoration 设置为 none 实际上比将 text-decoration 设置为“”要差一些。$("div").css("文本装饰", "")

不同之处在于,通过设置为空字符串,您实际上删除了 js 设置的属性。说,您的元素text-decoration: "underline"最初具有(在 css 中,在您使用 jQuery 设置值之前)。将其设置为“无”将是错误的。删除该属性会很好。

于 2011-07-28T12:26:55.003 回答
0

Javascript:document.getElementById(element_id).style.textDecoration = "none"

jQuery:$('#element_id').css("text-decoration", "none");

于 2011-07-28T12:21:27.573 回答
-1

将文本装饰设置为无

或者 document.getElementById(divID).style.removeAttribute("textDecoration",false)你可以从样式中删除 textDecoration (在 IE 中工作)

于 2011-07-28T12:16:24.200 回答