Javascript 如何让动态加载的元素在ajax调用后初始化?
我正在使用numericstepper.js作为输入文本框微调器。当我有以下代码时,它就工作了Javascript 如何让动态加载的元素在ajax调用后初始化?,javascript,php,jquery,ajax,jquery-plugins,Javascript,Php,Jquery,Ajax,Jquery Plugins,我正在使用numericstepper.js作为输入文本框微调器。当我有以下代码时,它就工作了 <script src="<?= site_url('assets/js/numericstepper.js') ?>"></script> <script> $('.continue-participation-btn').click(function(e) { e.preventDefault(); var $form = $('form[n
<script src="<?= site_url('assets/js/numericstepper.js') ?>"></script>
<script>
$('.continue-participation-btn').click(function(e) {
e.preventDefault();
var $form = $('form[name="apr-grade-participation-form"]').serialize();
$.ajax({
url: '/ajax/continue_participation',
type: 'POST',
data: $form,
success: function(res) {
if (res) {
$('.continuous-section').html(res);
$('html, body').animate({
scrollTop: 0
}, 900, function() {
$('.participation').removeClass('visible').addClass('completed-section');
$('.continuous-section').addClass('visible');
});
} else {
alert('Unable to process request');
}
}
});
});
</script>
<label for="">Number of Students</label>
<span class="numeric-stepper" style="display: block;">
<input size="2" class="number-of-day-input" id="day_<?=$part_count;?>" name="partdetail_pk_5[<?=$part_count;?>][day]" type="text" placeholder="000" pattern="[0-9]*" value="">
<button type="button" name="ns_button_1" maxValue = 999 value="1" class="plus">+</button>
<button type="button" name="ns_button_2" value="-1" class="minus">-</button>
</span>
您需要通过调用$('.numeric stepper').stepper()初始化新微调器在ajax调用的success函数中使用code>
$.ajax({
// other ajax options ...
success: function(res) {
if (res) {
$('.numeric-stepper').stepper();
...
谢谢塞缪尔编辑我的问题。我对stackoverflow很陌生……)您能否共享请求此内容并将其插入页面的代码?是否有任何错误发生?对于一些一般猜测:和/或在我添加$('.numeric').stepper()之后;我发现“UncaughtTypeError:$(…).stepper不是一个函数”错误我需要调用numberstepper.js中的initNumericStepper()来重新加载它。很抱歉造成混淆。但你的回答让我想到重新加载函数。谢谢你的帮助。