[已解决]旧版本的问题 // Jquery 帮助升级到最新版本

[RESOLVED ]Problem with an old version of // Jquery Help upgrade to last version

迁移到 jquery 3

后,我遇到代码问题

不工作:需要更新并需要删除 ui jquery 我想迁移到 3.6,但出现错误: https://jsfiddle.net/alex447/u817ybjk/1/

工作但旧版本: https://jsfiddle.net/alex447/c06tb5rL/28/

做得很少 jquery 我想查看最新 jquery 版本中的代码,并且没有 ui-query 以便显示进度条。

如果将代码更改为 1.5 版本 ui jquery 你可以看到我想要的最终结果。

如果我转到 jquery 3.4.1 或其他我有错误:

"jQuery.Deferred exception: $(...).progressbar is not a function", "TypeError: $(...).progressbar is not a function at HTMLDocument.<anonymous> (https://fiddle.jshell.net/_display/?editor_console=true:728:23) at mightThrow (https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js:3534:29) at process (https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js:3602:12)", undefined

谢谢

您必须添加 jQuery ui 库,(知道 progress() 函数属于最后一个),

它适用于以前的版本,因为它是一个已检查的输入,可以自动导入 ui,如您在此处所见:

添加主题 + jQuery ui cdn url 将解决此问题 jsFiddle

但是如果你想去掉 jQuery ui ,

您可以创建自己的进度,一些 css 和简单的 js,如下面的代码段所示:

$(document).ready(function() {
    
    $("#progressbar").css("width",0);
    
    $('[type*=radio]').click(function() {
        var totalChecked = 0;
        var totalRadioGroups = 0;
        var previousName = '';
        $.each($('[type*=radio]'), function(index, value) {
            var radioName = $(this).attr('name');
            var radioId = this.id;
            
            if (previousName != radioName) {
                totalRadioGroups++;
            }
            if ($('#' + radioId).is(':checked')) {
                totalChecked++;
            }
            previousName = radioName;
        });
        var percentage = (totalChecked / totalRadioGroups) * 100;
        $('#progressbar').css('width', percentage+"%");
        $('#progressbar').html(percentage.toFixed(2) + "%");
        
        $('#percentage').html(percentage.toFixed(2) + "%");
    });

});
#progress-container {
  width: 100%;
  border: 1px solid #ddd;
  height:25px;
  border-radius:5px;
  overflow:hidden;
}

#progressbar {
  height: 25px;
  background-color: #0412AD;
  text-align: center;
  line-height: 30px;
  color: white;
  width:0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

Question 1<br>
<div class="js-form-item">
  <input type="radio" name="radioQone" id="radioQ11">Option 1<br>
</div>
<div class="js-form-item">
<input type="radio" name="radioQone" id="radioQ12">Option 2<br>
</div>
<div class="js-form-item">
<input type="radio" name="radioQone" id="radioQ13">Option 3<br>
</div>
<br>Question 2<br>
<div class="js-form-item79">
<input type="radio" name="radioQtwo" id="radioQ21">Option 1<br>
</div>
<div class="js-form-item78">
<input type="radio" name="radioQtwo" id="radioQ22">Option 2<br>
</div>
<div class="js-form-item34">
<input type="radio" name="radioQtwo" id="radioQ23">Option 3<br>
</div>
<br>Question 3<br>
<div class="js-form-item111">
<input type="radio" name="radioQthree" id="radioQ31">Option 1<br>
</div>
<div class="js-form-item11">
<input type="radio" name="radioQthree" id="radioQ32">Option 2<br>
</div>
<div class="js-form-item3">
<input type="radio" name="radioQthree" id="radioQ33">Option 3<br>
</div>

<br>Question 3<br>
<div class="js-form-item5">
<input type="radio" name="radioQFOUR" id="radioQ35">Option 1<br>
</div>
<div class="js-form-item-">
<input type="radio" name="radioQFOUR" id="radioQ36">Option 2<br>
</div>
<div class="js-form-itemè">
<input type="radio" name="radioQFOUR" id="radioQ37">Option 3<br>
</div>
<br>
<div id="progress-container">
  <div id="progressbar">
    
  </div>
</div>
<div id="percentage">
  <p>fff</p>
</div>