[英]Set CSS style on selected text using JavaScript
I have a function that changes CSS styles when you select it from a dropdown. 当您从下拉列表中选择CSS样式时,我可以更改它的样式。 I'm using the
switch
function for the different CSS styles for the different cases. 我在不同情况下将
switch
函数用于不同的CSS样式。 How do I add styling to whatever element is selected? 如何为选定的任何元素添加样式?
onClick : function( value ){
switch (value) {
case "remove_border": remove_border(editor.getSelection().getSelectedText()); break;
}
}
function remove_border(selection) {
/* what must I put in here to make this function work? */
alert(selection);
}
Add an ID to your elements and do a getElementById(x); 为您的元素添加一个ID并执行getElementById(x);
If I'm misunderstanding, you might want to provide a jsfiddle so we can see what you're trying to do. 如果我误会了,您可能想提供一个jsfiddle,以便我们可以看到您正在尝试做什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.