我有以下js代码:
<script type="text/javascript">
jQuery(document).ready(function($){
// List of contributors quantities inputs
var honorCont = $('.honor-contributor input[type="number"]');
var premCont = $('.premium-contributor input[type="number"]');
var plusCont = $('.plus-contributor input[type="number"]');
var adultCont = $('.adult-contributor input[type="number"]');
var kidCont = $('.kid-contributor input[type="number"]');
var honorContPrevNum, premContPrevNum, plusContPrevNum, adultContPrevNum, kidContPrevNum;
honorContPrevNum = premContPrevNum = plusContPrevNum = adultContPrevNum = kidContPrevNum = 0;
// Hide the titles on DOM load
$('.honor-cont, .t-size, .prem-cont, .plus-cont, .adult-cont, .kid-cont').addClass('hide');
/* Honor contributor */
$(honorCont).change(function (){
var honorContUpdatedNum = honorCont.val();
if( honorContUpdatedNum > honorContPrevNum && honorContUpdatedNum > 1 ) {
gfRepeater_repeatRepeater(4, 1);
} else {
gfRepeater_unrepeatRepeater(4, 1);
}
if( honorContUpdatedNum > 0 ){
$('.honor-cont').removeClass('hide');
}
else{
$('.honor-cont').addClass('hide');
}
honorContPrevNum = honorContUpdatedNum;
});
/* Premium contributor */
$(premCont).change(function (){
var premContUpdatedNum = premCont.val();
if( premContUpdatedNum > premContPrevNum && premContUpdatedNum > 1 ) {
gfRepeater_repeatRepeater(4, 2);
} else {
gfRepeater_unrepeatRepeater(4, 2);
}
if( premContUpdatedNum > 0 ){
$('.prem-cont').removeClass('hide');
}
else{
$('.prem-cont').addClass('hide');
}
premContPrevNum = premContUpdatedNum;
});
/* Plus contributor */
$(plusCont).change(function () {
var plusContUpdatedNum = plusCont.val();
if( plusContUpdatedNum > plusContPrevNum && plusContUpdatedNum > 1 ){
gfRepeater_repeatRepeater(4, 3);
} else {
gfRepeater_unrepeatRepeater(4, 3);
}
if( plusContUpdatedNum > 0 ){
$('.plus-cont').removeClass('hide');
}
else{
$('.plus-cont').addClass('hide');
}
plusContPrevNum = plusContUpdatedNum;
});
/* Adult contributor */
$(adultCont).change(function () {
var adultContUpdatedNum = adultCont.val();
if( adultContUpdatedNum > adultContPrevNum && adultContUpdatedNum > 1 ) {
gfRepeater_repeatRepeater(4, 4);
} else {
gfRepeater_unrepeatRepeater(4, 4);
}
if( adultContUpdatedNum > 0 ){
$('.adult-cont').removeClass('hide');
}
else{
$('.adult-cont').addClass('hide');
}
adultContPrevNum = adultContUpdatedNum;
});
/* Kid contributor */
$(kidCont).change(function () {
var kidContUpdatedNum = kidCont.val();
if( kidContUpdatedNum > kidContPrevNum && kidContUpdatedNum > 1 ) {
gfRepeater_repeatRepeater(4, 5);
} else {
gfRepeater_unrepeatRepeater(4, 5);
}
if( kidContUpdatedNum > 0 ){
$('.kid-cont').removeClass('hide');
}
else{
$('.kid-cont').addClass('hide');
}
kidContPrevNum = kidContUpdatedNum;
});
});
</script>
当我调试这个时,我看到第一个更改事件是页面加载时触发,当它只在输入类型改变后才会触发,我想这与错误有关。知道为什么会这样吗?
提前致谢!
答案 0 :(得分:1)
我想问题出在你的功能中。您正在传递参数,您应该用逗号括起来:gfRepeater_repeatRepeater("<?php echo $als_campaign_form_id; ?>", 1);
尝试在所有功能中加入逗号,然后检查。感谢