[英]how to set css of text decoration strikethrough to red color using javascript
I want to have a red strikethrough, but it still ends up black. 我想有一个红色的删除线,但仍然以黑色结尾。 This is what I tried: 这是我尝试的:
.redRow {
text-decoration: line-through;
color: red;
}
Javascript code is: JavaScript代码是:
function getCurrentBinRow(elem) {
$(elem).closest('tr').toggleClass('redRow');
}
使用Java风格的文字装饰,
document.getElementById('redRow').style.textDecoration = "line-through";
Try to edit your CSS first, setting the color of a td in black and then you can apply your jQuery function: 首先尝试编辑CSS,将td的颜色设置为黑色,然后可以应用jQuery函数:
function getCurrentBinRow(elem) { $(elem).closest('tr').toggleClass('redRow'); } $(document).ready(function() { getCurrentBinRow('td'); });
td { color: black; } .redRow { text-decoration: line-through; color: red; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script> <table> <tr> <td>TEST</td> </tr> </table>
You have to give line through and color of line through, to the parent and the content should be in child element. 您必须将直通线和直通线的颜色提供给父级,并且内容应位于子元素中。
<span style="text-decoration: line-through; color: red;">
<span style="color: #CCC;">Your content</span>
So make your markup accordingly or please give a working fiddle. 因此,请相应地进行标记,或者进行工作。
I made it inline styles, Please move it to a class and make work with your stuff. 我制作了内联样式,请将其移至类中并使用您的东西。
If you need to do this on a onclick event. 如果需要在onclick事件上执行此操作。
<label onclick="addStrikethrough(this)">Test</label>
function addStrikethrough(element){
element.className = element.className + ' redRow';
}
The javascript function needs to be declared in the global namespace. javascript函数需要在全局名称空间中声明。
The css 的CSS
.redRow {
text-decoration: line-through;
color: red;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.