单选按钮甚至不会发射

Bri*_*ale 3 ajax jquery wordpress-plugin

我有这个html是根据我们数据库中的数据动态创建的.我正在尝试创建一个向导,以便当用户单击单选按钮时,我使用ajax调用webservice,并创建另一个单选按钮列表供用户选择.初始页面加载工作正常,但是当我创建动态单选按钮列表时,我遇到了触发事件的问题.我是否必须重新加载文档或特定div以使其工作?

我想在选择其中一个单选按钮时捕获"更改"事件.下面的jQuery没有捕获事件.关于我做错了什么的任何建议?

HTML:

<input name="productModel" id="Basic-jacketCustom" type="radio" value="Basic jacket"><label for="Basic-jacketCustom">Basic jacket</label>
<input name="productModel" id="Platinum-jacketCustom" type="radio" value="Platinum jacket"><label for="Platinum-jacketCustom">Platinum jacket</label>
<input name="productModel" id="Platinum-Pro-jacketCustom" type="radio" value="Platinum Pro jacket"><label for="Platinum-Pro-jacketCustom">Platinum Pro jacket</label>
<input name="productModel" id="Riding-jacketCustom" type="radio" value="Riding jacket"><label for="Riding-jacketCustom">Riding jacket</label>
Run Code Online (Sandbox Code Playgroud)

jQuery的:

$('input[name="productModel"]').change(function() {    alert("Event
 Fires"); });
Run Code Online (Sandbox Code Playgroud)

roN*_*n23 7

"动态创建"是什么意思?你是否在页面加载后将输入推送到dom?如果是,您必须使用事件委派.请尝试以下示例:

$('body').on('change', 'input[name="productModel"]', function() {
  alert("Event Fires");
});
Run Code Online (Sandbox Code Playgroud)