javascript 如何将 nowrap 属性设置为 td 元素?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5138324/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 16:06:44  来源:igfitidea点击:

How to set nowrap property to td element?

javascriptjquery

提问by JAB

This is what I tried:

这是我尝试过的:

function(nowrap)  {  
 var cell = $(`'<td>'`);  
 //cell.wrap = wrap (not working)   
}

回答by Paul Rowland

Try using nowrap attribute,

尝试使用nowrap 属性

<td nowrap="nowrap">

<td nowrap="nowrap">

Using css this should work with div element, not sure about td

使用 css 这应该适用于 div 元素,不确定 td

<style type="text/css">
.nowrap {
  white-space: nowrap;
}
</style>

<div class="nowrap">Content here</div>
<style type="text/css">
.nowrap {
  white-space: nowrap;
}
</style>

<div class="nowrap">Content here</div>

回答by Deepak

If you wanna get a particular tdfrom table and set its property, then try it.

如果您想td从表中获取特定信息并设置其属性,请尝试一下。

First give a unique class name or id to its td.

首先为其td.

Using the ID, write

使用ID,写

$('#td1").attr("nowrap","nowrap");

Using the class, write

使用类,写

$('.td1").attr("nowrap","nowrap");

回答by Steve Wellens

var $cell = $('td');  
$cell.css("white-space", "nowrap");

回答by Santosh Linkha

Use attrfunction. also check here. It says that NOWRAPis deprecated. Instead use CSS

使用attr功能。也在这里检查。它说这NOWRAP已被弃用。而是使用CSS

<script>
$(function() {        
       var cell = $('<td></td>').attr({'NOWRAP': 'NOWRAP'}).appendTo('.tr').html('asdfsd');  
});
</script>

<table>
    <tr class='tr'><tr>
</table>