2008-11-24 20 views
2

好吧,我是JQuery的新手,我有一個模式,它有一個asp:文字控制。文字由任何鏈接點擊激活模態控制。所以,我希望這會像給鏈接上的字面值onClick那麼簡單,但事實並非如此。JQuery模式下的ASP.NET控件

我很希望:文字的值是在頁面加載時設置的,所以我必須把它放在更新面板中,這樣當鏈接被點擊時它會改變。

或者它可能是:像JavaScript一樣,您必須用JQuery onClick動態設置文字的值。

謝謝你的幫助。

UPDATE

下面是模式的HTML:

<div class="modal-holder" id="landing-page-modal" style="display:none"> 
    <div class="modal"> 
    <div class="modal-t"> 
     <a href="#" class="modal-close"> 
     <img src="images/modal-close.gif" border="0" alt="" /> 
     </a> 
     <div class="modal-scroll"> 
     <a href="#" class="modal-top-arrow"> 
      <img src="images/modal-arr-t.gif" alt="" /> 
     </a> 
     <a href="#" class="modal-bottom-arrow"> 
      <img src="images/modal-arr-b.gif" alt="" /> 
     </a> 
     </div> 
     <div class="modal-b"> 
     <div class="modal-content"> 
      <h2><asp:Label ID="lblModal" Text="Title" runat="server" /></h2> 
      <p> 
      <asp:Literal ID="litModal" Text="Test Data Lives Here For Now" runat="server" /> 
      </p> 
     </div> 
     </div> 
    </div> 
    </div> 
</div> 

這是激活點擊一個鏈接時,該模式JQuery的:

$('.article a, #menu a, #features a').click(function(){ 
    $('.modal-holder').css({'display': 'block'}); 
    return false; 
}); 

$('.modal-close').click(function(){ 
    $('.modal-holder').css({'display': 'none'}); 
}); 

我想知道如何改變模態中「litModal」控制的值,然後才能激活它。

+0

發佈您具有HTML版本的樣本可能會有所幫助。你的解釋本身有點難以遵循。 – Tomalak 2008-11-24 07:51:56

回答

1

好吧,讓你的文字在你的<p>。這意味着你沒有直接的選擇器/句柄,就像你使用ID時的標籤一樣。

但你能說這是<div class="modal-content"><p>,ID爲landing-page-modal元素的所有部分:

"#landing-page-modal div.modal-content p" 

所以,你需要修改你的功能,使可見整個事情:

$('.article a, #menu a, #features a').click(function(clickTarget){ 
    // set the text of the <p> to whatever you like. I took 
    // the text of the element that was clicked by the user. 
    $('#landing-page-modal div.modal-content p').text($(clickTarget).text()); 

    // now make the whole thing visible 
    $('#landing-page-modal').css({'display': 'block'}); 
    return false; 
}); 
0

如果您希望模型在點擊鏈接時更改客戶端,您需要在鏈接的onClick處理程序中設置它。我假設模態文本是基於被點擊的錨點標記。 litModal將變成客戶端的一個跨度,所以我們可以這樣找到它。

$('.article a, #menu a, #features a').click(function(anchor){ 
      var val = jQuery(anchor).text(); 
      // modify val as needed 
      $('span#litModal').text( val); 
      $('.modal-holder').css({'display': 'block'}); 
      return false; 
    }); 
    $('.modal-close').click(function(){ $('.modal-holder').css({'display': 'none'}); }); 

注意:我假設您每頁只有一個。如果沒有,那麼你需要弄清楚如何引用適用於鏈接的特定模式。