简体   繁体   English

使用jQuery向表中添加一行后如何阻止文本突出显示

[英]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.

相关问题 是否可以停止选择和/或突出显示 jqGrid 行? - Is it possible to Stop jqGrid row(s) from being selected and/or highlighted? 使用jQuery将图像附加到MVC中的表行 - appending Image to a table row in mvc using jquery 如何使用 jquery 获取突出显示的文本位置 - how to get highlighted text positions using jquery 使用jQuery将html附加到div时如何阻止内容从屏幕外推送 - How do I stop content from being pushed outside of the screen when appending html to a div with jquery 使用javascript附加行后如何自动计算每个表行的总价? - How to automatically calculate the total price of each table row after appending the row using javascript? 如何防止在表中添加多次,一旦使用Jquery迫使它多次双击表行? - How to prevent appending multiple times in the table, Once It forcing to double click multiple times the table row using Jquery? 如何避免在禁用文本区域后仍突出显示选定文本? (铬合金) - How can I avoid selected text still being highlighted after text area is disabled? (Chrome) 使用 jquery 从表行请求文本返回 '' - Requesting text from a table row using jquery returns '' 使用jQuery附加文本后,如何删除文本区域底部的空换行符? - How can I remove the empty line break at the bottom of my textarea after appending text using jQuery? 如何阻止表再次构建 - How to stop the table from being built again
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM