在 Jquery 中追加

发布于 2024-11-29 13:36:46 字数 87 浏览 0 评论 0原文

我试图在复选框下附加按钮。按钮有类名,复选框有一个类名。当我尝试在复选框下附加按钮的类名称时,它会附加该类下的每个按钮。如何在每个复选框下附加每个按钮。 谢谢,

I was trying to append the button under the check box. The button have class name, check box have one classname. When I try to append with the class name of button under the checkbox, its appending every button under that class. How to append each button under each check box.
Thanks,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

波浪屿的海角声 2024-12-06 13:36:46

我认为您需要使用 .each jQuery 关键字循环遍历每个复选框并向每个复选框添加一个按钮。

不要认为您可以用一行代码来完成此操作。

因此,当您循环遍历“each”复选框时,您可以将 $(this) 与附加结合使用,将按钮附加到“each”复选框。

我希望这会有所帮助,因为您的问题有点模糊。

哦,并发布一些 html 和/或代码。这会有所帮助

,这里有一个可能有帮助的链接;

http://api.jquery.com/jQuery.each/

http://jeradbitner.com/content/jquery-checkbox-goodness

I think you need to use the .each jQuery keyword to loop through each checkbox and add a button to each one.

don't think you can do this in a single line of code.

So as you loop through "each" checkbox you can use $(this) in conjunction with the append to append the button to "each" checkbox.

I hope this helps as your question is a little vague.

Oh, and post some html and/or code. that would help a bit

here is a link that might help;

http://api.jquery.com/jQuery.each/

http://jeradbitner.com/content/jquery-checkbox-goodness

嘿嘿嘿 2024-12-06 13:36:46

以下内容将在分配了 CSS 类“myCheckbox”的每个复选框后附加一个按钮:

$(document).ready(function() {
    $('.myCheckbox').each(function(idx, el) {
         $(el).after('<input type="button" class="myButton" value="' + el.id + '"/>');
    });   
});

http://jsfiddle.net /34tkN/1/

正如其他人提到的,很难完全理解您的要求。澄清一下,我可以更新我的回复。

The following will append a button after each checkbox that is assigned the CSS class "myCheckbox":

$(document).ready(function() {
    $('.myCheckbox').each(function(idx, el) {
         $(el).after('<input type="button" class="myButton" value="' + el.id + '"/>');
    });   
});

http://jsfiddle.net/34tkN/1/

As others have mentioned, it's hard to fully understand what you are asking for. Clarify and I can update my response.

不必在意 2024-12-06 13:36:46

你可以尝试这样的事情:

<script>

   var btHtml = '<button class="lolButton">LOL</button>';
   $(".chkBox").append(btHtml);

</script>

You can try something like:

<script>

   var btHtml = '<button class="lolButton">LOL</button>';
   $(".chkBox").append(btHtml);

</script>
梦罢 2024-12-06 13:36:46

复选框代码:

<div class="chkCompare>
    <input type="checkbox" onclick="CompareCheckChanged(this,'60c0ca0d-b68d-4edd-b667-0d4320b60ede');" name="mrpPhones$ctl00$chkCompare" id="mrpPhones_ctl00_chkCompare">
    <span style="margin-left: 5px;">Compare</span>
</div>

按钮代码:

<a style="display: inline-block; width: 85px; font-weight: normal;" href="javascript:__doPostBack('mrpPhones$ctl00$lineItemPrice$lnkbtnAddToCart','')" class="button-genericsprite green-button-23cart" title="Add to cart" id="mrpPhones_ctl00_lineItemPrice_lnkbtnAddToCart" onclick="javascript:hideProgressBar();">
    <span style="font-size: 12px;">Add to Cart</span>           
</a>

复选框位于左侧,按钮位于右侧。我想将按钮放在复选框下。对于每个复选框,应该有一个按钮。当我尝试附加按钮的类名时,所有按钮都位于复选框下。我只想在一个复选框下放置一个按钮。

chech box code:

<div class="chkCompare>
    <input type="checkbox" onclick="CompareCheckChanged(this,'60c0ca0d-b68d-4edd-b667-0d4320b60ede');" name="mrpPhones$ctl00$chkCompare" id="mrpPhones_ctl00_chkCompare">
    <span style="margin-left: 5px;">Compare</span>
</div>

button code:

<a style="display: inline-block; width: 85px; font-weight: normal;" href="javascript:__doPostBack('mrpPhones$ctl00$lineItemPrice$lnkbtnAddToCart','')" class="button-genericsprite green-button-23cart" title="Add to cart" id="mrpPhones_ctl00_lineItemPrice_lnkbtnAddToCart" onclick="javascript:hideProgressBar();">
    <span style="font-size: 12px;">Add to Cart</span>           
</a>

Check box is at left hand side, button is at right side. I want to put button under check box. For each check box one button should come. When I am trying to append with the class name of the button all the buttons are coming under check box. I want only one button come under one check box.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文