我们都知道,当我们在浏览器中选择一个文本部分时,它的背景颜色会变成蓝色。我已经使用::selection 伪元素来更改背景颜色,如下面的代码所示。
::selection {
background: pink;color: yellow;
}
::-moz-selection {
background: pink;color: yellow;
}
看我的例子here 但是::selection 不支持 IE9 以下版本。请检查提供的浏览器兼容性表this page一次。我需要在 IE9 以下版本中应用相同的属性。谁能告诉我执行此操作的另一种方法。提前致谢
最佳答案
一种使用 jquery 的方法
<script type="text/javascript">
$('document').ready(function(){
$("#textfield").focus(function () {
$('.class').css(' background-color','#ffe823');
});
});
<input type="text" class="class" name="textfield" id="textfield" >
关于javascript - 当用户在浏览器中选择文本时,有没有办法改变背景颜色(对于 IE9 以下版本),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10312472/