Jquery没有在.load页面中执行

时间:2016-08-23 08:34:23

标签: javascript jquery html

我的.load函数存在问题。加载的页面没有在加载的div中执行Jquery。我确保Jquery确实在标签中。我在想.load调用存在问题,但我是新手。有什么想法吗?

<script type="text/javascript">
var partyid = '<?php echo sanitize_text_field($_GET["Party_ID"]); ?>';
jQuery(document).ready( function($){
    if (localStorage.user2==localStorage.username2){
        var e = document.getElementById('display');
        if(e.style.display == 'block')
            e.style.display = 'none';

        $('#Submission-2').load('http://example.com/play/?Party_ID=' + partyid + ' #Submission' );
        refresh();
    }
});
</script>

<script type="text/javascript">
function refresh() 
{ 
    setTimeout( function() { 
        $('#Submission-2').fadeOut('slow').load('http://example.com/play/?Party_ID=' + partyid + ' #Submission'  , function() {
            var username = '<?php echo $party_information[0]->Username; ?>';
            if (document.getElementById('total').value!=username){
                window.location.reload();
            }
        });
        $('#Submission-2').fadeIn('slow').load('http://example.com/play/?Party_ID=' + partyid + ' #Submission' );
        {
            refresh();
        }
    }, 5000); 
}
</script>

未执行的Jquery

<script type="text/javascript">
jQuery("#Answertoggle3 .lietruth").click(function(){
    jQuery("#Answertoggle3 .lietruth").removeClass('active');
    jQuery(this).toggleClass('active'); 
});
jQuery("#Answertoggle2 .lietruth").click(function(){
    jQuery("#Answertoggle2 .lietruth").removeClass('active');
    jQuery(this).toggleClass('active'); 
});
jQuery("#Answertoggle1 .lietruth").click(function(){
    jQuery("#Answertoggle1 .lietruth").removeClass('active');
    jQuery(this).toggleClass('active'); 
});
</script>

也代替执行window.location.reload();功能。我想结束包含函数refresh()的执行。每5秒后刷新一次。所以基本上停止刷新。

2 个答案:

答案 0 :(得分:0)

根据我对你的问题的理解,试试这样的事情:

<script type="text/javascript">
    $(document).ready(function(){
        $("#Answertoggle3 .lietruth").click(function(){
                $("#Answertoggle3 .lietruth").removeClass('active');
                $(this).toggleClass('active'); 
        });
        $("#Answertoggle2 .lietruth").click(function(){
                $("#Answertoggle2 .lietruth").removeClass('active');
                $(this).toggleClass('active'); 
        });
        $("#Answertoggle1 .lietruth").click(function(){
                $("#Answertoggle1 .lietruth").removeClass('active');
                $(this).toggleClass('active'); 
        });
    })
</script>

答案 1 :(得分:0)

这是我添加的内容,它使切换工作暂时通过fadeOut.load和fadeIn。当这是真的时,我需要停止执行refresh()函数。

if (document.getElementById('total').value!=username)

而不是

window.location.reload();

的Javascript

<script type="text/javascript">
function refresh() 
{ 
var quitfunction = 0;
 setTimeout( function() { 
$('#Submission-2').fadeOut('slow').load('http://example.com/play-with-friends/?Party_ID=' + partyid + ' #Submission' ,function() {
jQuery("#Answertoggle3 .lietruth").click(function(){
        jQuery("#Answertoggle3 .lietruth").removeClass('active');
        jQuery(this).toggleClass('active'); 
});
jQuery("#Answertoggle2 .lietruth").click(function(){
        jQuery("#Answertoggle2 .lietruth").removeClass('active');
        jQuery(this).toggleClass('active'); 
});
jQuery("#Answertoggle1 .lietruth").click(function(){
        jQuery("#Answertoggle1 .lietruth").removeClass('active');
        jQuery(this).toggleClass('active'); 
});
var username = '<?php echo $party_information[0]->Username; ?>';
if (document.getElementById('total').value!=username)
{
window.location.reload();
}
        });
$('#Submission-2').fadeIn('slow').load('http://example.com/play-with-friends/?Party_ID=' + partyid + ' #Submission' );
{
if (quitfunction==1)
return;
refresh();
}
 }, 5000); 
}
</script>