使用 jQuery 将文本换行在 <nobr> 标记内

wrap text inside <nobr> tag using jquery

本文关键字:nobr jQuery 文本 换行 使用      更新时间:2023-09-26

我有<nobr>标签中的共享点 gererate 标签。但是在页面上它太长了,我需要使用 jquery 包装它。

<td nowrap="true" valign="top" width="113px" class="ms-formlabel"><h3 class="ms-standardheader">
    <nobr>On a scale of 1 to 10, with 1 being the lowest and 10 the highest, please rate your overall satisfaction with the management and implementation of this project?  Rating:</nobr>
</h3></td>

更好的选择是删除<nobr>标签。是否可以根据文本删除?因为页面上还有其他许多其他<nobr>标签。

尝试这样做:

$('.ms-formlabel nobr').css('white-space', 'normal');

<nobr> 标签通常具有 CSS white-space nowrap

如果您需要删除 nobr 标签并保留文本,您应该

var text = $(".ms-formlabel nobr").html()
$(".ms-formlabel h3").html(text);

如果您只想删除 nobr 标签并删除文本,只需:

$(".ms-formlabel nobr").remove();

好的,所以听起来你被迫接收<nobr>标签。 如果我是你,我会将它们转换为<p>标签。

$('nobr').each(function() {
    $(this).after('<p>' + $(this).html() + '</p>');
    $(this).remove();
});

如果您只想将文本保留在其中,请使用 .text() 而不是 .html() . 您也可以使用 <div /> 而不是 <p /> 标记。