jquery code在code pen中工作,但在vs code中不工作

g6ll5ycj  于 2023-08-04  发布在  jQuery
关注(0)|答案(1)|浏览(165)

我有一个Next按钮,它应该转到表单中的下一个字段集。它在代码笔(https://codepen.io/atakan/pen/nPOZZR)中工作,我发现它。也有人问过同样的问题,但解决方案应该只是添加jquery cdn调用,但没有工作。有人知道这是怎么回事吗?(没有错误消息,我使用的是Django版本4.2.3)这个html:

  1. <!-- multistep form -->
  2. {%load static%}
  3. <head>
  4. <!-- ... your other links and scripts ... -->
  5. <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
  6. <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.easing.min.js"></script>
  7. <script src="{% static 'assets/js/profile_completion.js' %}"></script>
  8. <link rel="stylesheet" href="{% static 'assets/css/profile_completion.css' %}">
  9. </head>
  10. <body>
  11. <form id="msform">
  12. <!-- progressbar -->
  13. <ul id="progressbar">
  14. <li class="active">Account Setup</li>
  15. <li>Social Profiles</li>
  16. <li>Personal Details</li>
  17. </ul>
  18. <!-- fieldsets -->
  19. <fieldset>
  20. <h2 class="fs-title">Create your account</h2>
  21. <h3 class="fs-subtitle">This is step 1</h3>
  22. <input type="text" name="email" placeholder="Email" />
  23. <input type="password" name="pass" placeholder="Password" />
  24. <input type="password" name="cpass" placeholder="Confirm Password" />
  25. <input type="button" name="next" class="next action-button" value="Next" />
  26. </fieldset>
  27. <fieldset>
  28. <h2 class="fs-title">Social Profiles</h2>
  29. <h3 class="fs-subtitle">Your presence on the social network</h3>
  30. <input type="text" name="twitter" placeholder="Twitter" />
  31. <input type="text" name="facebook" placeholder="Facebook" />
  32. <input type="text" name="gplus" placeholder="Google Plus" />
  33. <input type="button" name="previous" class="previous action-button" value="Previous" />
  34. <input type="button" name="next" class="next action-button" value="Next" />
  35. </fieldset>
  36. <fieldset>
  37. <h2 class="fs-title">Personal Details</h2>
  38. <h3 class="fs-subtitle">We will never sell it</h3>
  39. <input type="text" name="fname" placeholder="First Name" />
  40. <input type="text" name="lname" placeholder="Last Name" />
  41. <input type="text" name="phone" placeholder="Phone" />
  42. <textarea name="address" placeholder="Address"></textarea>
  43. <input type="button" name="previous" class="previous action-button" value="Previous" />
  44. <a href="https://twitter.com/GoktepeAtakan" class="submit action-button" target="_top">Submit</a>
  45. </fieldset>
  46. </form>
  47. </body>

字符串
这个JavaScript:

  1. //jQuery time
  2. var current_fs, next_fs, previous_fs; //fieldsets
  3. var left, opacity, scale; //fieldset properties which we will animate
  4. var animating; //flag to prevent quick multi-click glitches
  5. $(".next").click(function(){
  6. if(animating) return false;
  7. animating = true;
  8. current_fs = $(this).parent();
  9. next_fs = $(this).parent().next();
  10. //activate next step on progressbar using the index of next_fs
  11. $("#progressbar li").eq($("fieldset").index(next_fs)).addClass("active");
  12. //show the next fieldset
  13. next_fs.show();
  14. //hide the current fieldset with style
  15. current_fs.animate({opacity: 0}, {
  16. step: function(now, mx) {
  17. //as the opacity of current_fs reduces to 0 - stored in "now"
  18. //1. scale current_fs down to 80%
  19. scale = 1 - (1 - now) * 0.2;
  20. //2. bring next_fs from the right(50%)
  21. left = (now * 50)+"%";
  22. //3. increase opacity of next_fs to 1 as it moves in
  23. opacity = 1 - now;
  24. current_fs.css({
  25. 'transform': 'scale('+scale+')',
  26. 'position': 'absolute'
  27. });
  28. next_fs.css({'left': left, 'opacity': opacity});
  29. },
  30. duration: 800,
  31. complete: function(){
  32. current_fs.hide();
  33. animating = false;
  34. },
  35. //this comes from the custom easing plugin
  36. easing: 'easeInOutBack'
  37. });
  38. });
  39. $(".previous").click(function(){
  40. if(animating) return false;
  41. animating = true;
  42. current_fs = $(this).parent();
  43. previous_fs = $(this).parent().prev();
  44. //de-activate current step on progressbar
  45. $("#progressbar li").eq($("fieldset").index(current_fs)).removeClass("active");
  46. //show the previous fieldset
  47. previous_fs.show();
  48. //hide the current fieldset with style
  49. current_fs.animate({opacity: 0}, {
  50. step: function(now, mx) {
  51. //as the opacity of current_fs reduces to 0 - stored in "now"
  52. //1. scale previous_fs from 80% to 100%
  53. scale = 0.8 + (1 - now) * 0.2;
  54. //2. take current_fs to the right(50%) - from 0%
  55. left = ((1-now) * 50)+"%";
  56. //3. increase opacity of previous_fs to 1 as it moves in
  57. opacity = 1 - now;
  58. current_fs.css({'left': left});
  59. previous_fs.css({'transform': 'scale('+scale+')', 'opacity': opacity});
  60. },
  61. duration: 800,
  62. complete: function(){
  63. current_fs.hide();
  64. animating = false;
  65. },
  66. //this comes from the custom easing plugin
  67. easing: 'easeInOutBack'
  68. });
  69. });


我尝试添加不同版本的jQuery。

guykilcj

guykilcj1#

解决了。脚本在DOM准备好之前就已经运行了,所以我只添加了:

  1. $(document).ready(function(...))

字符串

相关问题