0

特定のリンクが代わりに JQuery ロードを使用するスクリプトを作成しようとしています

これは動作しません。

function inload() {
$('#sausage').load(this.attr('href') + ' #sausage');
return false;
}

問題は私の t にあると思いますが、his.attr('href')アドバイスが必要です。

何か案は?

素晴らしい

4

3 に答える 3

1
$("a").live("click",function(e){  //.live not .click so the function will also work on the newly loaded content

    e.preventDefault(); //prevent the default action of clicking the link

    var href = $(this).attr("href"); //grab the links href

    $("body").load(href,callback); //load the contents of the href info the body of the page

});

//added a callback for running after the content has loaded if required
function callback(){
    alert("content loaded");
}
于 2011-03-18T16:59:15.007 に答える
0

に到達するには、実際にタグを使用していると仮定して、これhrefを簡単に行うことができます。this.href<a/>thisDom Element

function inload() {
  $('#sausage').load(this.href + ' #sausage');
  return false;
}

それ以外の場合は使用$(this).attr('href');

于 2011-03-18T17:01:42.460 に答える
0

する必要があります

$('#sausage').load($(this).attr('href')+'#sausage');

また

$('#sausage').load(this.href+'#sausage');
于 2011-03-18T16:59:40.080 に答える