【问题标题】:JQuery -- What is the correct syntax for targeting a div by a "constructed" ID?JQuery - 通过“构造”ID 定位 div 的正确语法是什么?
【发布时间】:2018-03-11 04:53:45
【问题描述】:

我正在编写一个函数来隐藏一个 div 并将其所有单选按钮清除为未选中状态。

我通过使用变量将其 ID 拼凑在一起来定位 div,如下所示:

$('#'+target).hide();

我想清除里面的所有单选按钮,但我不知道正确的语法。以下不起作用。我该如何解决?

$('('#'+target) :radio').prop('checked', false);

【问题讨论】:

    标签: jquery syntax radio-button


    【解决方案1】:

    您可以将所有内容附加到同一个选择器中,也可以像这样使用 find 作为子选择器:

    $('#'+target+' :radio').prop('checked', false);$('#'+target).find(':radio').prop('checked', false);

    【讨论】:

      猜你喜欢
      • 2015-05-04
      • 2016-02-05
      • 1970-01-01
      • 2020-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-03
      相关资源
      最近更新 更多