English 中文(简体)
使用相对路径时,每个孩子都会 Jquery. each when use else path?
原标题:Jquery .each when using relative path?

使用相对路径( 而不仅仅是类名 ) 时, 我无法找到如何让每个人工作 。 这是为了正确检查是否选中了收音机按钮, 但是它会继续为他们同时制作.radio_ select 显示 。 因此它显然只是检查第一个值, 然后将结果应用到两个值, 当我想单独检查的时候。 有人能发现我做错了什么吗? 是否有更好的方法可以这样做? 感谢帮助, 谢谢 。

<div id= pid ></div>

<div class= comment_reply_holder >

<div class="radio_holder">
<div class= radio_select >
<input class= hidden_radio  type= radio  checked= true >
</div>
</div>

<div class="radio_holder">
<div class= radio_select >
<input class= hidden_radio  type= radio >
</div>
</div>

</div>

<script>
radio = $( # +pid).next( .comment_reply_holder ).children().find( .radio_holder );
radio.each(function() {
if (radio.children().find( .hidden_radio ).prop("checked") == true) {
radio.children().find( .radio_select ).show();
}
});
</script>

注意 : “ Pid” div 是在网站上动态创建的, 这就是为什么我以这种方式获取信息, 如果你想知道为什么我甚至以这种方式创建了通往它的道路。

最佳回答

只需在回调函数中使用 this (即当前迭代元素), 而不是外部变量 radio

问题回答
radio.each(function(i,elem) {
  if (elem.children().find( .hidden_radio ).prop("checked") == true) {
    elem.children().find( .radio_select ).show();
  }
});

你为什么用无线电?

radio.each(function(i, item) {
   if (item.children().find( .hidden_radio ).prop("checked") == true) {
   item.children().find( .radio_select ).show();
}




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

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签