【问题标题】:Manipulate ::selection with jquery使用 jquery 操作 ::selection
【发布时间】:2016-08-08 07:41:47
【问题描述】:

我只是想在函数上这样做

function changeGenre(toWhat) {
    [...]
    $('::selection').css("background-color",'rgb('+color+')');
}

但它似乎不起作用。为什么?

编辑:::selection 不是 DOM 元素,所以我正在寻找解决此问题的替代方法。

【问题讨论】:

  • color 变量贴花在哪里?你的html在哪里?你在哪里以及如何打电话给changeGenre
  • 我使用[...] 无缘无故地不向您展示整个功能。颜色已声明并在我的代码中多次使用,并且可以正常工作。例如,在同一个函数中,我有 $('.cover').css("background-color","rgb("+color+")"); 并且它可以工作。此外,changeGenre 在按钮单击时被调用,它具有onclick 属性@John

标签: javascript jquery html css


【解决方案1】:

尝试将其与 css 类一起使用:请参阅此帖子:Set the text selection color with jQuery. Demo not working

$(document).ready(function(){
	changeGenre();
});

function changeGenre() {
    $('p').addClass("gr");
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

<style>
p.gr::selection {
    background:#ff0099;
}
</style>

<p><strong>Note:</strong> ::selection is not supported in Internet Explorer 8 and earlier versions.</p>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-31
    • 1970-01-01
    • 1970-01-01
    • 2020-05-09
    • 1970-01-01
    相关资源
    最近更新 更多