JQuery 中的字符串比较?

发布于 2024-11-18 17:51:54 字数 1350 浏览 5 评论 0原文

我正在研究下面提到的 JQuery

jQuery("select[name='hideLineItemColumns_quote'] option:selected").each(function () {

    var columnName = $.trim($(this).text());


    $('thead.line-item-grid-header tr th').filter(function () {

        return $.trim($('div', this).text()) == columnName;
    }).hide();

});

因此,根据 Select 标签的选定选项,Jquery 将隐藏表中的相应列。一切工作正常,除了一种情况,当columnName =“List Price”时,它不起作用。如果我特别提到“标价”,

return $.trim($('div', this).text()) == "List Price";

效果很好。我有什么遗漏的吗?

下面是选择下拉列表的 html

<select name="hideLineItemColumns_quote" multiple="true" style="width:100%;" size="4" class="form-input ">
<option value="__part_desc">Description</option>
<option value="__part_number">Product</option>
<option value="_costEa_line">Cost</option>
<option value="_listPriceEach_line">List&nbsp;Price</option>
</select>

,下面是 thead 的代码

<thead class="line-item-grid-header">
    <tr>
        <th align="center" class="list-label ">
            <div style="overflow:hidden;width:60px;">List Price</div>
        </th>
    </tr>
</thead>

,它看起来像而不是在 firebug 中显示 &nbsp; 的空格,有什么解决方法吗?

谢谢, 尼泰什

I am working on JQuery mentioned below

jQuery("select[name='hideLineItemColumns_quote'] option:selected").each(function () {

    var columnName = $.trim($(this).text());


    $('thead.line-item-grid-header tr th').filter(function () {

        return $.trim($('div', this).text()) == columnName;
    }).hide();

});

So based on the selected option of the Select tag, Jquery will hide respective columns in a table. Everything is working fine except one scenario, when columnName = "List Price" it doesn't work. If I specifically mention "List Price" in

return $.trim($('div', this).text()) == "List Price";

it works fine. Is there anything I am missing?

Below is the html for select dropdown

<select name="hideLineItemColumns_quote" multiple="true" style="width:100%;" size="4" class="form-input ">
<option value="__part_desc">Description</option>
<option value="__part_number">Product</option>
<option value="_costEa_line">Cost</option>
<option value="_listPriceEach_line">List Price</option>
</select>

and below is code for thead

<thead class="line-item-grid-header">
    <tr>
        <th align="center" class="list-label ">
            <div style="overflow:hidden;width:60px;">List Price</div>
        </th>
    </tr>
</thead>

it looks like instead of space it showing   in firebug, any workaround ?

Thanks,
Nitesh

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

带刺的爱情 2024-11-25 17:51:54

不间断空格(U+00A0 Unicode,十进制 160,& nbsp;) 与空格字符不同(U+0020 Unicode,十进制 32)。好吧,他们两个看似是一个“空间”,但却是完全不同的角色。

一种可能的解决方法是,在检查时将不间断空格转换为简单空格:

$.trim($('div', this).text()) == columnName.replace(/\u00A0/g, ' ')

jsFiddle 演示

The non-breaking space (U+00A0 Unicode, 160 decimal,  ) is not the same as the space character (U+0020 Unicode, 32 decimal). Well, both of them seems to be a "space", but they are absolutely different characters.

One possible workaround is that for the time of checking you convert non-breaking spaces into simple spaces:

$.trim($('div', this).text()) == columnName.replace(/\u00A0/g, ' ')

jsFiddle Demo

一世旳自豪 2024-11-25 17:51:54

您的 HTML 中有 List Price,它不等于代码中的“List Price”。

You have List Price in your HTML which is not equal to "List Price" in code.

清醇 2024-11-25 17:51:54

最好使用 :contains()

 $("div:contains('List Price')")

另请参阅 :contains() jquery.com/jQuery.contains/" rel="nofollow">jQuery.contains

better you use :contains()

 $("div:contains('List Price')")

also see jQuery.contains

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文