Javascript Jquery高亮显示文本的选定值
我试图让我的编辑器,当你在你的计算机上突出显示文本时,jquery将把选择的值和周围的标签,更具体的代码或预标签抛出Javascript Jquery高亮显示文本的选定值,javascript,jquery,Javascript,Jquery,我试图让我的编辑器,当你在你的计算机上突出显示文本时,jquery将把选择的值和周围的标签,更具体的代码或预标签抛出 var Selectedvalue = // set highlighted selection value $("#content").contents().find("body").append($("<pre></pre>").append(Selectedvalue)) ; var Selectedvalue=//
var Selectedvalue = // set highlighted selection value
$("#content").contents().find("body").append($("<pre></pre>").append(Selectedvalue))
;
var Selectedvalue=//设置突出显示的选择值
$(“#content”).contents().find(“body”).append($(“”)。append(Selectedvalue))
;
我已经知道如何获取标签之间的值,我只需要知道如何获取值。试试这样的方法
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
$(function()
{
var ifx = $('<iframe src="code/sample.html" height=200 width=200></iframe>').appendTo(document.body);
$(document.body).bind('mouseover', function()
{
var u_sel;
if(window.getSelection)
{
u_sel = ifx[0].contentWindow.getSelection();
alert(u_sel);
}
});
});
</script>
}好吧,通过几次谷歌搜索,我确信这就是它 对OP评论的回应
$(函数()
{
var ifx=$('').appendTo(document.body);
$(document.body).bind('mouseover',function()
{
var u__sel;
if(window.getSelection)
{
u_sel=ifx[0].contentWindow.getSelection();
警报(u_sel);
}
});
});
这对将来的参考很有用,但我忘了提到它是用于iframe xD的。你认为你能帮我吗?我自己没有试过,但我在答案中添加了测试过的工作代码,请根据需要设置。
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
$(function()
{
var ifx = $('<iframe src="code/sample.html" height=200 width=200></iframe>').appendTo(document.body);
$(document.body).bind('mouseover', function()
{
var u_sel;
if(window.getSelection)
{
u_sel = ifx[0].contentWindow.getSelection();
alert(u_sel);
}
});
});
</script>