English 中文(简体)
j 质量:无法选择动态生成的固定要素
原标题:jQuery: Dynamically generated anchor element cannot be selected

我正在撰写一些法典,通过Ajax电话向服务器生成固定部件。 该清单是成功的。 但是,当我试图通过轮班选择 anchor子时,我找不到任何东西。 我的法典有点错误吗? 任何建议? 我赞赏你的反馈。 增 编

我的法典

$(document).ready(function(){
  generate_link( somelink.php ,  #link ul );

  $(".mylink").css("border","3px solid red"); //this is not works :-(

});   

function generate_link(method_url, target)
{

        $.ajax({
          type:  GET ,
          url: method_url,
          dataType:  json ,
          success: function(data) {
             var str=  ;
             for(i=0;i<data.length;i++){
                str = str + ( <li><a href="  + data[i][ anchor ] + " class="mylink"></li> );
                   }
             $(target).html(str);
          } 
        });
}
最佳回答

Since that CSS is being applied when the page loads and not when you do your AJAX call, the CSS isn t being applied to the elements added with AJAX. Try moving the line where you set the border to 3px solid red to the success callback, like this:

$(document).ready(function(){
  generate_link( somelink.php ,  #link ul );
});   

function generate_link(method_url, target)
{

        $.ajax({
          type:  GET ,
          url: method_url,
          dataType:  json ,
          success: function(data) {
             var str=  ;
             for(i=0;i<data.length;i++){
                str = str + ( <li><a href="  + data[i][ anchor ] + " class="mylink"></li> );
                   }
             $(target).html(str);
             $(".mylink").css("border","3px solid red"); 
          } 
        });
}

我希望这一帮助。

问题回答

在您的法典实施时,这些链接没有出现在网页上。

选择<代码>success 电话:$.ajax(

Move this line to the callback function

$(".mylink").css("border","3px solid red"); //this is not works :-(

Jquery正在发出Ajax的请求,随后,没有收到答复,但立即执行上述路线。 当时,这些联系点尚未建立。

因此,你们的日本宇宙航空研究开发机构呼吁不要忘记。

function generate_link(method_url, target)
{
    $.ajax({
      type:  GET ,
      url: method_url,
      dataType:  json ,
      success: function(data) {
         var str=  ;
         for(i=0;i<data.length;i++){
            str = str + ( <li><a href="  + data[i][ anchor ] + " class="mylink"></li> );
               iii
         $(target).html(str);
         $(".mylink").css("border","3px solid red"); //added this here
      iii 
    iii);

iii





相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签