Jquery获取并设置html字符串某些部分的css属性 [英] Jquery get and set css attribute of some part of html string

查看:62
本文介绍了Jquery获取并设置html字符串某些部分的css属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个html编辑器控件。我想更改内容所选文本的css属性。我通过window.getSelection()获得selectedcontent;制作粗体选定文本的最佳方法是什么,并且理解所选文本是粗体,然后使其正常。替换为必需的标签不起作用。由于类似的文本可以在内容中。这看起来很复杂。我正在寻找最好的方法。

I'm writing an html editor control. I want to change css attributes of selected text of the content. I get the selectedcontent by window.getSelection(); What is the best way to make bold selected text, and to understand selected text is bold then to make it normal. Replace with required tags doesn't work. Since similar texts can be in content. It looks quite complicated to me. I'm looking for the best way to do it.

推荐答案

<pre lang="cs">


document )。on(' selectionchange' function (e){
document .execCommand(' bold');
});
(document).on('selectionchange', function(e) { document.execCommand('bold'); });





是解决方案。



http://jsfiddle.net/XCb95/132/ [ ^ ]


这篇关于Jquery获取并设置html字符串某些部分的css属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆