带有哈希(#)的Ajaxpageloak,当有数字时例外(例如:#1)

I'm using this code:

<script type='text/javascript'>
$(document).ready(function () {

    //Check if url hash value exists (for bookmark)
    $.history.init(pageload);  

    //highlight the selected link
    $('a[href=' + document.location.hash + ']').addClass('selected');

    //Seearch for link with REL set to ajax
    $('a[rel=ajax]').click(function () {

        //grab the full url
        var hash = this.href;

        //remove the # value
        hash = hash.replace(/^.*#/, '');

        //for back button
        $.history.load(hash);  

        //clear the selected class and add the class class to the selected link
        $('a[rel=ajax]').removeClass('selected');
        $(this).addClass('selected');

        //hide the content and show the progress bar
        $('#ajax').hide();
        $('#loading').show();

        //run the ajax
        getPage();

        //cancel the anchor tag behaviour
        return false;
    });
});


function pageload(hash) {
    //if hash value exists, run the ajax
    if (hash) getPage();   
}

function getPage() {

    //generate the parameter for the php script
    var data = 'page=' + document.location.hash.replace(/^.*#/, '');
    $.ajax({
        url: "loader.php", 
        type: "GET",       
        data: data,    
        cache: false,
        success: function (html) { 

            //hide the progress bar
            $('#loading').hide();  

            //add the content retrieved from ajax and put it in the #content div
            $('#ajax').html(html);

            //display the body with fadeIn transition
            $('#ajax').fadeIn('slow');      
        }      
    });
}
</script>

So I have to use: page to run the ajax ... However, I am using in some places:

Go to some <a href='#1'> notices </ a> for example ... And when you click, instead of just driving to the id = '1 ', is doing the ajax code to run.

How do I add an exception and not when you run the code number in the hash?

If you want to check the existence of a digit in your hash string, you can easily use RegExp. This way you can create a pattern and check a string :

var pattern = new RegExp(/.*[0-9].*/);
pattern.test(hash); // Will return TRUE if it contains any digit.

You can add an exception by adding a check to see if the hash is an integer or not. See code below. (I've only adjusted the $('a[rel=ajax]') section, the rest of the code is fine as is.)

//Search for link with REL set to ajax
$('a[rel=ajax]').click(function () {

    //grab the full url
    var hash = this.href;

    //remove the # value
    hash = hash.replace(/^.*#/, '');

    // test if hash is not an integer
    if(parseInt(hash) != hash){

        //for back button
        $.history.load(hash);  

        //clear the selected class and add the class class to the selected link
        $('a[rel=ajax]').removeClass('selected');
        $(this).addClass('selected');

        //hide the content and show the progress bar
        $('#ajax').hide();
        $('#loading').show();

        //run the ajax
        getPage();

        //cancel the anchor tag behaviour
        return false;
    }
});