代码之家  ›  专栏  ›  技术社区  ›  Sara Chipps

jquery模式下的ASP.NET控件

  •  2
  • Sara Chipps  · 技术社区  · 16 年前

    好的,我是jquery的新手,我有一个模式,其中包含一个asp:literal控件。文本由单击任何链接激活模式来控制。所以,我希望它能像在链接上一键给出文字值一样简单,但事实并非如此。

    我希望:文本的值是在页面加载时设置的,所以我必须将其放入更新面板中,以便在单击链接时更改。

    或者可能是:像javascript一样,您必须使用jquery onclick动态地设置文本的值。

    谢谢你的帮助。

    更新

    下面是模式的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”控件的值。

    2 回复  |  直到 16 年前
        1
  •  1
  •   Tomalak    16 年前

    好吧,你的文字 <p> . 这意味着您没有直接的选择器/句柄,就像它是带有ID的标签时那样。

    但你可以说是 <P & GT; 里面 <div class="modal-content"> ,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;
    });
    
        2
  •  0
  •   tvanfosson    16 年前

    如果您希望模式在单击链接时更改客户端,则需要在链接的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'}); });
    

    注意:我假设每页只有一个。如果没有,那么您需要了解如何引用应用于所讨论链接的特定模式。