JQuery if label contains this ...这样做 [英] JQuery if label contains this... do this

查看:122
本文介绍了JQuery if label contains this ...这样做的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网页上有asp.net中继器。如果每个重复的项目都包装在如下标签中:

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>

如果此标签包含文本35,我想在其旁边显示一些文本。我如何使用jquery做这个

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";
        }
    });


推荐答案


  1. .ready 函数应该引用文档。 li>
  2. 要获取文本内容,请使用 .text()而不是 .val() obj.val()= blah; 。 (这实际上是Javascript的限制。)

  3. 有一个 :contains() selector 来过滤包含一些文本的元素。

  4. 要附加一些文字(或HTML),已有 .append()方法(感谢@JP提醒这个。)

  1. The this in the .ready function should refer to the document.
  2. To get the text content, use .text() instead of .val().
  3. To update some value, use $obj.val(blah);, not $obj.val() = blah;. (This is actually a limitation of Javascript.)
  4. There is a :contains() selector to filter elements containing some text.
  5. To append some text (or HTML), there is already an .append() method (Thanks @J-P for reminding this.)

您可能希望改为:

$('.ItemName:contains(35)').append("some text");

这篇关于JQuery if label contains this ...这样做的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆