当用户单击单选框时,如何使用 Jquery 显示隐藏的 DIV?

发布于 2024-09-01 09:14:27 字数 539 浏览 2 评论 0原文

当用户选择单选框时,我很难显示隐藏的 div。

这是我的代码:

Jquery

<script>
$(document).ready(function () {
  $(".paypalmethod").click(function() {
  $(".paypalinfo").show('slow');

});

</script>

html

<input name="method" type="radio" value="paypal" class="paypalmethod"/><img src="/images/paymentlogos/PayPal.png" />

<div class="paypalinfo" style="display:none">Paypal the safe and easy way to pay. Paypal accepts all major credit cards.</div>

I am having difficulty showing a hidden div when a user selects a radio box.

This is my code:

The Jquery

<script>
$(document).ready(function () {
  $(".paypalmethod").click(function() {
  $(".paypalinfo").show('slow');

});

</script>

The html

<input name="method" type="radio" value="paypal" class="paypalmethod"/><img src="/images/paymentlogos/PayPal.png" />

<div class="paypalinfo" style="display:none">Paypal the safe and easy way to pay. Paypal accepts all major credit cards.</div>

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

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

发布评论

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

评论(2

半城柳色半声笛 2024-09-08 09:14:28

您在代码中缺少关闭 });,您需要关闭 document.ready.click(),例如另外

$(document).ready(function () { //or just $(function() { works here as well
  $(".paypalmethod").click(function() {
    $(".paypalinfo:hidden").show('slow');
  });
});

,为了在元素已经可见时不产生淡入淡出,请添加 :hidden< /code> 选择器就像我上面的那样。这使得它仅在当前隐藏的元素中查找/淡入,并且在元素已经显示时不会重新淡入。

You're missing a closing }); in your code, you need to close the document.ready and the .click(), like this:

$(document).ready(function () { //or just $(function() { works here as well
  $(".paypalmethod").click(function() {
    $(".paypalinfo:hidden").show('slow');
  });
});

Also, to not produce a fade when the element's already visible, add a :hidden selector in like I have above. This makes it only find/fade in the element if it's currently hidden, and wont re-fade it in when it's already shown.

彩虹直至黑白 2024-09-08 09:14:28

这是一个语法错误。您需要关闭第二个函数和 jQuery 调用:

<script>
$(document).ready(function () {
  $(".paypalmethod").click(function() {
    $(".paypalinfo").show('slow');
  });
});

</script>

It's a syntax error. You need to close your second function and jQuery call:

<script>
$(document).ready(function () {
  $(".paypalmethod").click(function() {
    $(".paypalinfo").show('slow');
  });
});

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