2011-09-19 32 views
0

我有一個偉大的模態腳本我正在使用,通過ajax加載頁面。但是,href保留爲空白。這意味着我需要爲每個鏈接創建一個新的ID。他們的方法是隻用一個腳本來使用它,並通過ajax加載正確的鏈接,並將標題作爲鏈接中的標題。 這是腳本。加載模態的阿賈克斯

<a id="ajax2" href="#" onClick="self.location=this.href; return false"> 
    $('#ajax2').click(function(){ 
     lightbox.alert({ 
      width: '400px', 
      title: 'Gamerholic.com Sign Up/Log In', 
      rightButtons: ['Close'], 
      background: 'black', 
      fade: 'false', 

      opened: function(){ 
       $('<span />').load('./login.php').appendTo('#lbContent'); 
      }, 
      buttonClick: function(button){ 
       console.log(button); 
      } 
     }); 
    }); 

回答

0

我真的不明白你的問題。你想要一個動態鏈接,它提供了一個網址和標題?

我創建了一個類,它抓住了鏈接的href +標題並在代碼中使用它,這是你的意思嗎?

<a class="classname" href="./login.php" title="your title"> 

你JS:

$('.classname').click(function(){ 
     var url = $(this).attr('href'); //get the attribute href 
     var title = $(this).attr('title'); //get the attribute href 

     lightbox.alert({ 
     width: '400px', 
     title: title, 
     rightButtons: ['Close'], 
     background: 'black', 
     fade: 'false', 

     opened: function(){ 
      $('<span />').load(url).appendTo('#lbContent'); 
     }, 
     buttonClick: function(button){ 
      console.log(button); 
     } 
    }); 
    return false; 
}); 
0

如果我理解正確你的問題:

<a class="ajax" href="#" url="login.php" title="Login" onClick="self.location=this.href; return false"> 
<a class="ajax" href="#" url="register.php" title="Register" onClick="self.location=this.href; return false"> 
$('.ajax').click(function(){ 
    lightbox.alert({ 
     width: '400px', 
     title: $(this).attr('title'), 
     rightButtons: ['Close'], 
     background: 'black', 
     fade: 'false', 

     opened: function(){ 
      $('<span />').load($(this).attr('url')).appendTo('#lbContent'); 
     }, 
     buttonClick: function(button){ 
      console.log(button); 
     } 
    }); 
});