本文介绍了直到页面重新加载后,JavaScript / JQuery才能正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 此代码已列在我所有网页的标题中。当我点击我网站上的链接时,我无法使用页面上的按钮,直到我刷新。我该如何解决这个问题? < script src =https://code.jquery.com/jquery-2.1。 3.min.js>< /脚本> < script type =text / javascript> $(document).ready(function(){ $('。faqElement')。click(function(){ var faqElement = $(this); var question = faqElement.find('。faqQuestion'); var answer = faqElement.find('。faqAnswer'); if(!answer.hasClass('activeFaqAnswer')){ $('。faqElement')。removeClass('flipButton'); faqElement.addClass('flipButton'); $('。activeFaqAnswer')。css('max-height','' ); $('。faqAnswer')。removeClass('activeFaqAnswer'); answer.css('max-height','none'); answer.css('max ()); answer.addClass('activeFaqAnswer'); } }); }); < / script> 解决方案这听起来像是与您的自定义脚本冲突, a Squarespace的AJAX加载:$ b $ hs = b 所以,根据您的模板,您可能会发现禁用AJAX是一个简单的解决方案:So, depending on your template, you may find that disabling AJAX is a simple solution:If you do not want to disable AJAX altogether, then inserting something like the following via Header code injection is often the way to go (on newer templates, such as the Brine/Wright family):<script> (function() { // Establish a function that does something. var myCustomFunction = function() { // Do stuff here. }; // Initialize the fn on site first-load. document.addEventListener("DOMContentLoaded", myCustomFunction); // Reinit. the fn on each new AJAX-loaded page. window.addEventListener("mercury:load", myCustomFunction); })();</script>If that doesn't work, then you have to setup a mutation observer on the body element to watch for attribute changes, notably the id. At time of writing, such an approach was necessary for the York/Doncab family of templates.Note that for some pages, such as the /cart/ page, this method may not execute as intended, creating an additional need for either setInterval, requestAnimationFrame or a mutation observer method mentioned previously. 这篇关于直到页面重新加载后,JavaScript / JQuery才能正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-18 21:14