Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如果单个单选按钮是动态添加的,如何识别它们?_Php_Jquery_Button_Dynamic_Radio - Fatal编程技术网

Php 如果单个单选按钮是动态添加的,如何识别它们?

Php 如果单个单选按钮是动态添加的,如何识别它们?,php,jquery,button,dynamic,radio,Php,Jquery,Button,Dynamic,Radio,我有两个单选按钮:“是”和“否”。如果我选择“是”,将出现一个输入文本框,如果我选择“否”,文本框将隐藏 问题在于单选按钮是通过下拉菜单(数字1-30)动态添加的。 它们当前的设置如下所示: <li> <input type="radio" id="yes-sdf-1" name="field[0][sdfradio]" value="Yes" /> <label for="yes-sdf-1">Yes</label> &l

我有两个单选按钮:“是”和“否”。如果我选择“是”,将出现一个输入文本框,如果我选择“否”,文本框将隐藏

问题在于单选按钮是通过下拉菜单(数字1-30)动态添加的。

它们当前的设置如下所示:

<li>
    <input type="radio" id="yes-sdf-1" name="field[0][sdfradio]" value="Yes" />
    <label for="yes-sdf-1">Yes</label>
    <input type="text" name="field[0][sdf-text]" style="display: none;" />
</li>
<li>
    <input type="radio" id="no-sdf-1" name="field[0][sdfradio]" value="No" checked />
    <label for="no-sdf-1">No</label>
</li>
但正如你所看到的,只有在有一个sdfradio的情况下,这才能起作用。如果我使用类似于
name=“field[count\u goes\u here][sdfradio]”的数组

在动态生成元素的情况下使用jQuery进行事件委派,我该如何让它工作

另外,使用
*=
-jQuery

$(document).on('change',':radio[name*="sdfradio"]',function() {
    ....
});

我看不到ID为
sdf text
-
$('input#sdf text')
input的引用

您需要
$(':text[name*=“sdfradio”]')

$(document).on('change',':radio[name*="sdfradio"]',function() {
    ....
});