JQuery 如果标签包含这个...执行此操作
我的页面上有 asp.net 中继器。如果重复的每个项目都包含在一个标签中,如下所示:
<label class="ItemName">value</label>
如果该标签包含文本“35”,我想在其旁边显示一些文本。我怎样才能使用 jquery 做到这一点???
jQuery(document).ready(function () {
if ($('.ItemName').val().indexOf("35")) {
$(this).val() = $(this).val() + "some text";
}
});
I have asp.net repeater on a page. If each item being repeated is wrapped in a label like so:
<label class="ItemName">value</label>
If this label contains the text '35' I want to display some text next to it. How can i do this using jquery???
jQuery(document).ready(function () {
if ($('.ItemName').val().indexOf("35")) {
$(this).val() = $(this).val() + "some text";
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
.ready
函数中的this
应引用document
。.text()
而不是.val()
。$obj.val(blah);
,而不是$obj.val() = blah;
。 (这实际上是Javascript的限制。):contains()
选择器 过滤包含某些文本的元素。.append()
方法(感谢@JP提醒这一点。)您可能需要这个:
this
in the.ready
function should refer to thedocument
..text()
instead of.val()
.$obj.val(blah);
, not$obj.val() = blah;
. (This is actually a limitation of Javascript.):contains()
selector to filter elements containing some text..append()
method (Thanks @J-P for reminding this.)You may want this instead:
.text()
应该可以工作:.text()
should work:indexOf
如果未找到则返回 -1,否则返回索引。这样做:indexOf
returns -1 if not found, or the index. Do this:你的意思是这个?
this you mean?