JQuery 中的字符串比较?
我正在研究下面提到的 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 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 中显示
的空格,有什么解决方法吗?
谢谢, 尼泰什
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不间断空格(U+00A0 Unicode,十进制 160,
& nbsp;
) 与空格字符不同(U+0020 Unicode,十进制 32)。好吧,他们两个看似是一个“空间”,但却是完全不同的角色。一种可能的解决方法是,在检查时将不间断空格转换为简单空格:
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:
jsFiddle Demo
您的 HTML 中有
List Price
,它不等于代码中的“List Price”。You have
List Price
in your HTML which is not equal to "List Price" in code.最好使用 :contains()
另请参阅 :contains() jquery.com/jQuery.contains/" rel="nofollow">jQuery.contains
better you use :contains()
also see jQuery.contains