简体   繁体   English

限制 jQuery 的范围

[英]Limit scope of jQuery

var tr0HTML = $('<tr id="exp_line1"></tr>').appendTo(tbody);

What could the best possible way to use .css or any other jQuery to style this element based on the condition?使用 .css 或任何其他 jQuery 来根据条件设置此元素样式的最佳方法是什么?

All I could see is that the change has been implemented to whole page not for the particular scenario!我所能看到的是,更改已实施到整个页面,而不是针对特定场景!

Update: I want to style borders to the table which has 3 different types of rows.更新:我想为具有 3 种不同类型行的表格设置边框样式。 Rows are being displayed if the data is provided.如果提供了数据,将显示行。

If I have understood your question... Something as simple as this should work:如果我理解你的问题......像这样简单的事情应该可以工作:

 tr.type-1 td{ border: 2px solid hotpink; } tr.type-2 td{ border: 2px solid purple; } tr.type-3 td{ border: 2px solid black; }
 <table> <tbody> <tr class="type-1"> <td>Type 1</td> </tr> <tr class="type-2"> <td>Type 2</td> </tr> <tr class="type-3"> <td>Type 3</td> </tr> </tbody> </table>

Your jQuery code would look like this: $('<tr id="exp_line1" class='type-1'></tr>').appendTo(tbody)您的 jQuery 代码如下所示: $('<tr id="exp_line1" class='type-1'></tr>').appendTo(tbody)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM