【问题标题】:How to select an element using jquery? [duplicate]如何使用 jquery 选择元素? [复制]
【发布时间】:2014-09-19 15:58:37
【问题描述】:

我正在尝试在多个 div 中选择我的单选按钮值,但我不知道。

另外,在表格中附加文本但它不起作用。也许我的语法有误?

我也尝试过 appendTo() 但相同。屏幕上什么都没有显示

输入电台位于..

<div id="wrap">
<div id="section1">
<table class="question">
<tr><td><input type="radio" value="yes" name="tv"/></td><td><p id="position"></p></td></tr>
</table>
</div>
</div>

下面是我在 script.js 中的 jquery 源代码

$('#section1.input:radio["tv"]').change(function(){
    if ($(this).val() == 'yes') {
       $('#position').append("test appending");
});

【问题讨论】:

标签: jquery html


【解决方案1】:

你的选择器完全错误。

  • input 不应以点为前缀,它不是 CSS 类;
  • #section1input 之间需要一个空格,因为输入是 div 的子元素;
  • 您忘记了括号中的name=

尝试类似:

$('#section1 input:radio[name="tv"]').change(function(){
    if ($(this).val() == 'yes') {
       $('#position').append("test appending");
    }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="wrap">
  <div id="section1">
  <table class="question">
  	<tr>
      <td>
        <input type="radio" value="yes" name="tv"/></td><td><p id="position"></p>
      </td>
    </tr>
  </table>
  </div>
</div>

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-05
  • 2019-05-21
  • 2011-11-19
相关资源
最近更新 更多