在页面中添加新输入未运行脚本
new input added in page not run script
当我使用 (.load()) 重新加载 DIV 中的内容时,我的网站有问题单选按钮不运行 onchange 事件 我该如何解决?
$(window).ready(function(){
$('input[name="optionsRadios"]').on('change', function(){
if ($(this).val()=='veloce') {
//change to "show update"
var senzasped = <?php echo $tot; ?>;
senzasped += 5;
$("#prezzotot").text(senzasped);
$("#spedizionese").text("Spedizione Veloce");
$("#spedizionese2").text("5,00€");
} else {
var senzasped = <?php echo $tot; ?>;
senzasped += 3.5;
$("#prezzotot").text(senzasped);
$("#spedizionese").text("Spedizione Normale");
$("#spedizionese2").text("3,50€");
}
});
});
.HTML:
<div class="modal-sped" style="width:100%; height:100px">
<div class="row">
<div class="col-md-12" style="margin-left:20px">
<label>Selezione la spedizione: </label>
<div class="radio">
<label>
<input type="radio" name="optionsRadios" id="optionsRadios1"value="normale" checked>
Spedizione Normale 3,50€
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="optionsRadios" id="optionsRadios2" value="veloce">
Spedizione <strong>Veloce</strong> 5,00€
</label>
</div>
</div>
</div>
</div>
您需要
将事件绑定到未更改或未document
的元素:
$(document).on('change', 'input[name="optionsRadios"]', function() {
这是因为您附加更改侦听器的元素被替换为load
,并且新输入没有附加任何侦听器。如果将侦听器附加到未删除的document
或其他父元素,它将适用于存在或将要插入的所有匹配输入。
相关文章:
- 如何通过获取用户输入和使用按钮来运行JavaScript函数
- 如何在运行总计计算器时返回表单输入并更新 JavaScript 变量
- 提交输入时运行函数
- 当输入被禁用或重新启用时,如何运行函数
- 使用HTML中的输入来运行函数
- 如何将word文档中的值作为输入传递到javascript的文本框中,并在循环中运行它
- 从按钮读取文本并输入并运行
- 尝试通过输入字符串使程序停止运行
- EmberJS:将输入值绑定到控制器属性,并在更改时运行过滤器
- 在页面中添加新输入未运行脚本
- 使用 setTimeout 在不阻止输入的情况下运行大型任务,并使用 Promise 找出任务何时完成
- 我希望只有在HTML5表单输入经过验证后才能运行javascript函数
- jQuery,如果文件输入扩展名.pdf则运行函数
- 我可以在运行时检索输入类型的名称值
- 在jQuery中调用表单输入并运行函数
- 当输入字段上有某些 CSS 类时,Javascript 将不会运行
- 当用户在输入字段上按 Enter 时如何运行函数
- 无线电输入点击功能不会运行
- 我想在加载时运行这个 jquery,而不是它的样子,我应该如何输入代码
- javascript,jQuery同时使用两个不同的输入运行单个函数