English 中文(简体)
通行证
原标题:Passing ID Attributes
  • 时间:2011-11-18 16:43:22
  •  标签:
  • jquery
  • scope

我在利用每个功能而感到悲伤,但我遇到麻烦,无法将我带往我的模式箱。 该守则是:

(function() {
$( div.heriyah ).each(function() { 
$(this).html( <div class="add"><div id="add_button_container"><div id="add_button" class="edit_links">+ ADD NEW CONTENT</div></div></div><div class="clear"></div><div class="placeable"></div></div> );

$( .add ).click(function() {
$.fallr( show , {
          content     :   <iframe width="620" height="600" src="<? echo $URL ?>/manage_content.php?id=<? echo $pageID; ?>&div= +$(this).attr( id )+ "></iframe> ,
          width       : 620 + 5, // 100 = for width padding
          height         : 600,
          closeKey        : true,
          closeOverlay    : true,
          buttons     : {}
}); 
}); 

}); 

(iii)

如果我请求在我的示范箱内实现变数,我就获得<代码>。

我这样做:

 +$(this).attr( id )+ 

To grab the id inside my modal box function.

Thanks, Drummer

最佳回答

我不肯定<条码>的落码,但试图将你的代码改为:

    (function() {
    $( div.heriyah ).each(function() { 
    $(this).html( <div class="add"><div id="add_button_container"><div id="add_button" class="edit_links">+ ADD NEW CONTENT</div></div></div><div class="clear"></div><div class="placeable"></div></div> ); 

    var curID = $(this).attr( id );//get the id before you go into fallr

    $( .add ).click(function() {
    $.fallr( show , {
              content     :   <iframe width="620" height="600" src="<? echo $URL ?>/manage_content.php?id=<? echo $pageID; ?>&div= +curID + "></iframe> ,
              width       : 620 + 5, // 100 = for width padding
              height         : 600,
              closeKey        : true,
              closeOverlay    : true,
              buttons     : {}
    }); 
    }); 

    }); 
})();
问题回答

You are referencing $(this) from within the SECOND anonymous function. So you are asking for the $(this) of .add not the div.heriyah That is why you re not getting the ID.

这是因为,“现在指的是 fall倒。

$( .add ).click(function() {
    var _this = $(this);
    $.fallr( show , {
              content     :   /manage_content.php?id=&div= +_this+ "> ,
              width       : 620 + 5, // 100 = for width padding
              height         : 600,
              closeKey        : true,
              closeOverlay    : true,
              buttons     : {}
    }); 
}); 

在你正在建立<代码>iframe时,$(this)$( .add ),not

Before you bind the click event, just create a new variable and store $(this).attr( id ), and use that value instead.

classic scope issue - You re trying to get the id attribute of the .add element because you re in that scope.

a. 在<代码>each上加固(这一)美元的功能和使用:

$( div.heriyah ).each(function() {
$(this).html( <div class="add"><div id="add_button_container"><div id="add_button"      class="edit_links">+ ADD NEW CONTENT</div></div></div><div class="clear"></div><div class="placeable"></div></div> );

var that = $(this);

$( .add ).click(function() {
    $.fallr( show , {
          content     :   <iframe width="620" height="600" src="<? echo $URL ?>/manage_content.php?id=<? echo $pageID; ?>&div= +that.attr( id )+ "></iframe> ,
          width       : 620 + 5, // 100 = for width padding
          height         : 600,
          closeKey        : true,
          closeOverlay    : true,
          buttons     : {}
}); 
    }); 

}); 




相关问题
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: &...

热门标签