[英]How to stop text from being highlighted after appending a row to a table using jQuery
I am appending a row to a table using jQuery. 我正在使用jQuery向表中添加一行。 My code looks like:
我的代码如下:
var tbody = $("#properties tbody");
tbody.empty();
tbody.append(
"<tr>" +
"<td class='first'>State</td>" +
"<td>" + element.state + "</td>" +
"</tr>"
);
tbody.append(
"<tr>" +
"<td>Probability</td>" +
"<td>" + element.prob.toFixed(6) + "</td>" +
"</tr>"
);
The problem is that, after doing this, the text in the table is highlighted. 问题在于,执行此操作后,表中的文本将突出显示。 How can I stop that from happening?
我该如何阻止这种情况的发生?
Here is a JSFiddle reproducing the problem: http://jsfiddle.net/pzjeavwo/ 这是一个JSFiddle重现该问题的方法: http : //jsfiddle.net/pzjeavwo/
Thanks! 谢谢!
I checked your fiddle and the table row is not highlighted upon creation. 我检查了您的小提琴,并在创建时未突出显示表格行。 However, if, after creating the row, I double-click, it will be highlighted - but that is true for any html content that you double-click on any web page, so it looks like your code is working fine!
但是,如果在创建行之后双击,它将高亮显示-但是对于在任何网页上双击的任何html内容都是如此,因此您的代码看起来可以正常工作!
Try adding the following CSS to the element whose text is being highlighted. 尝试将以下CSS添加到突出显示其文本的元素中。
-webkit-user-select:none;
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
So it may looking something like this in your css code 所以它可能在您的CSS代码中看起来像这样
.first {
-webkit-user-select:none;
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
}
user-select disables highlighting https://developer.mozilla.org/en-US/docs/Web/CSS/user-select 用户选择禁用突出显示https://developer.mozilla.org/zh-CN/docs/Web/CSS/用户选择
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.