나는이 코드를 사용하고 있습니다 :Ajaxpageloak는 수있을 때 (예 : # 1)
<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>
그래서 내가 사용해야 ... 페이지를 아약스를 실행을하지만 어떤 장소에서 사용하고 있습니다 :
예를 들어, <a href='#1'> notices </ a>
으로 이동하십시오. 그리고 id = '1'로 운전하는 대신, 클릭하여 실행하는 아약스 코드를 수행하고 있습니다.
해시에서 코드 번호를 실행할 때 예외를 어떻게 추가합니까?
이 작품 .. :) 나는 추가 : \t var 패턴 = 새 RegExp (/.* [0-9]. * /); if (pattern.test (hash)! = true) {} –