【问题标题】:Adding title tag on check box select and .html() value在复选框选择和 .html() 值上添加标题标签
【发布时间】:2013-07-26 06:38:44
【问题描述】:

我需要在选中复选框时添加“标题”及其文本以突出显示...

我已经编写了以下 jquery 来做 iy,但它似乎没有工作。

              $('.ddcl-ddlPresentingIssue').closest('.ui-dropdownchecklist-text').html('Hello');
              $('.ddcl-ddlPresentingIssue').closest('.ui-dropdownchecklist-text').attr("title", 'Helo');

但它没有在 html 和标题标签中设置值.. 然后我尝试了同样的方式..

$('.ddcl-ddlPresentingIssue .ui-dropdownchecklist-text').html('Hello');
$('.ddcl-ddlPresentingIssue .ui-dropdownchecklist-text').attr("title", 'Helo');

即使它仍然不起作用。我想知道这里出了什么问题。

【问题讨论】:

    标签: jquery checkbox checkboxlist


    【解决方案1】:

    阅读选择器。在 Jquery 中 # 用于 ids

    选择器因此变成了

    $('#ddcl-ddlPresentingIssue .ui-dropdownchecklist-text').html('Hello').attr('title','Helo');
    

    【讨论】:

      【解决方案2】:

      你需要# 代替. 在你的第二次尝试这样-

      $('#ddcl-ddlPresentingIssue .ui-dropdownchecklist-text').html('Hello');
      

      ddcl-ddlPresentingIssue 是一个 ID


      如果您使用find() 代替closest()# 代替.,您的第一个示例将起作用

      $('#ddcl-ddlPresentingIssue').find('.ui-dropdownchecklist-text').html('Hello');
      

      【讨论】:

      • tnx 很多。我的错,我错过了# :-|
      【解决方案3】:

      使用#ddcl-ddlPresentingIssue,因为它是如图所示的 id。

      # 用于id 选择器,将. 用于类选择器。

       $('#ddcl-ddlPresentingIssue').closest('.ui-dropdownchecklist-text').html('Hello');
      

      【讨论】:

        【解决方案4】:

        您使用了错误的选择器:ddcl-ddlPresentingIssue 是跨度上的 ID。

        在 jQuery 和 CSS 中,您使用 # 作为 ID,使用 . 作为类。

        $('#ddcl-ddlPresentingIssue .ui-dropdownchecklist-text').html('Hello');
        $('#ddcl-ddlPresentingIssue .ui-dropdownchecklist-text').attr("title", 'Helo');
        

        【讨论】:

          猜你喜欢
          • 2019-05-04
          • 2019-02-08
          • 1970-01-01
          • 1970-01-01
          • 2019-01-07
          • 2017-04-08
          • 2017-09-07
          • 2016-02-18
          • 2017-05-04
          相关资源
          最近更新 更多