Javascript函数影响页面中指定以外的其他区域

Javascript函数影响页面中指定以外的其他区域,javascript,jquery,ajax,Javascript,Jquery,Ajax,但是由于某些原因,此代码也会影响登录和注销链接,我不希望发生这种情况 我最近才添加了#ajax#链接,试图解决这个问题,因为我以前使用过#主菜单ul li a和#logo a 谁能告诉我如何解决这个问题吗?首先,id属性应该是唯一的。将所有这些链接更改为使用类: var hash = window.location.hash.substr(1); var href = $('#ajax_link').each(function(){ var href = $(this).

但是由于某些原因,此代码也会影响登录和注销链接,我不希望发生这种情况

我最近才添加了#ajax#链接,试图解决这个问题,因为我以前使用过#主菜单ul li a和#logo a


谁能告诉我如何解决这个问题吗?首先,
id
属性应该是唯一的。将所有这些链接更改为使用类:

var hash = window.location.hash.substr(1);
    var href = $('#ajax_link').each(function(){
        var href = $(this).attr('href');
        if(hash==href.substr(0,href.length-4)){
            var toLoad = hash+'.html #content';
            $('#content').load(toLoad)
        }                                           
    });
    $('a').click(function(){                      
        var toLoad = $(this).attr('href')+' #content';
        $('#content').fadeOut('fast',loadContent);
        window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length);
        function loadContent() 
        {
            $('#content').load(toLoad,'',showNewContent())
        }
        function showNewContent() 
        {
            $('#content').fadeIn('normal');
        }
        return false;
    });


首先,
id
属性应该是唯一的。将所有这些链接更改为使用类:

var hash = window.location.hash.substr(1);
    var href = $('#ajax_link').each(function(){
        var href = $(this).attr('href');
        if(hash==href.substr(0,href.length-4)){
            var toLoad = hash+'.html #content';
            $('#content').load(toLoad)
        }                                           
    });
    $('a').click(function(){                      
        var toLoad = $(this).attr('href')+' #content';
        $('#content').fadeOut('fast',loadContent);
        window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length);
        function loadContent() 
        {
            $('#content').load(toLoad,'',showNewContent())
        }
        function showNewContent() 
        {
            $('#content').fadeIn('normal');
        }
        return false;
    });


首先,
id
属性应该是唯一的。将所有这些链接更改为使用类:

var hash = window.location.hash.substr(1);
    var href = $('#ajax_link').each(function(){
        var href = $(this).attr('href');
        if(hash==href.substr(0,href.length-4)){
            var toLoad = hash+'.html #content';
            $('#content').load(toLoad)
        }                                           
    });
    $('a').click(function(){                      
        var toLoad = $(this).attr('href')+' #content';
        $('#content').fadeOut('fast',loadContent);
        window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length);
        function loadContent() 
        {
            $('#content').load(toLoad,'',showNewContent())
        }
        function showNewContent() 
        {
            $('#content').fadeIn('normal');
        }
        return false;
    });


首先,
id
属性应该是唯一的。将所有这些链接更改为使用类:

var hash = window.location.hash.substr(1);
    var href = $('#ajax_link').each(function(){
        var href = $(this).attr('href');
        if(hash==href.substr(0,href.length-4)){
            var toLoad = hash+'.html #content';
            $('#content').load(toLoad)
        }                                           
    });
    $('a').click(function(){                      
        var toLoad = $(this).attr('href')+' #content';
        $('#content').fadeOut('fast',loadContent);
        window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length);
        function loadContent() 
        {
            $('#content').load(toLoad,'',showNewContent())
        }
        function showNewContent() 
        {
            $('#content').fadeIn('normal');
        }
        return false;
    });


$('ajax\u link')。每个
将只选择一个元素,因为ID是唯一的。
$('ajax\u link')。每个
将只选择一个元素,因为ID是唯一的。
$('ajax\u link')。每个
将只选择一个元素,因为ID是唯一的。
$('ajax\u link'))。每个
将只选择一个元素,因为ID是唯一的。好吧,我应该看到我只是长时间地盯着它看。我现在已经更改了它,但它仍然不起作用。正如它转到index.php/#login.php而不是login.phpOk一样,我应该看到我只是长时间地盯着它看了太久。我现在已经更改了它,但它仍然不起作用。正如它转到index.php/#login.php而不是login.phpOk一样,我应该看到我只是长时间地盯着它看了太久。我现在已经更改了它,但它仍然不起作用。正如它转到index.php/#login.php而不是login.phpOk一样,我应该看到我只是长时间地盯着它看了太久。我现在已经更改了它,但它仍然不起作用。因为它转到index.php/#login.php,而不仅仅是login.php
$('.ajax_link').each(function(){
   ....