javascript - Jquery 显示/隐藏 div onclick 单选按钮 - 根本不起作用

标签 javascript jquery

我花了很多时间,已经尝试了我能在网上找到的所有东西。没有任何效果!

作为标题,我需要在单击 radio 时简单地显示/隐藏 div。我测试了用链接替换单选按钮并且成功了!但对于单选按钮什么也没有

Javascript

$(document).ready(function(){
    $('.div_entrega_outro').hide();
    $("input[id$='entrega_outro']").click(function() {
        $('.div_entrega_outro').show();
    });

    $("input[id$='entrega_mesmo']").click(function() {
        $('.div_entrega_outro').hide();
    });
});

HTML

<input name="outro_endereco_entrega" id="entrega_mesmo" type="radio" value="N" > <label for="InputName">Entregar no endereço de cadastro</label><br>
<input name="outro_endereco_entrega" id="entrega_outro" type="radio" value="S" > <label for="InputName">Entregar em outro endereço</label>

<div class="div_entrega_outro" >
    bla bla bla
</div

我已经尝试过:

if($('input:radio[name=outro_endereco_entrega]:checked').val() == "N") 

$('#entrega_mesmo').click(function ()

链接测试:

link1/ link2/ link3 - working without radio

按照sideroxylon提示,我做了,但没有成功。我对 javascript 很不好:-(

$(document).ready(function(){
    $('.div_entrega_outro').hide();
    if($('.iradio_square_green:first').hasClass('checked')) {

            $('.div_entrega_outro').show();
    };
});

最佳答案

似乎正在使用您的代码。我没有改变任何东西。也许您的页面上有什么东西搞砸了?

$('.div_entrega_outro').hide();
$("input[id$='entrega_outro']").click(function() {
  $('.div_entrega_outro').show();
});

$("input[id$='entrega_mesmo']").click(function() {
  $('.div_entrega_outro').hide();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input name="outro_endereco_entrega" id="entrega_mesmo" type="radio" value="N"> <label for="InputName">Entregar no endereço de cadastro</label><br>
<input name="outro_endereco_entrega" id="entrega_outro" type="radio" value="S"> <label for="InputName">Entregar em outro endereço</label>

<div class="div_entrega_outro">
  bla bla bla
</div>

关于javascript - Jquery 显示/隐藏 div onclick 单选按钮 - 根本不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45339922/

相关文章:

javascript - 使用 CSS 的逐个字母的文本外观动画

javascript - 可以将 Wordpress 插件转换为在非 WP 网站上使用吗?

javascript - 列表中的按钮,如何使其 ''编辑''好行?

javascript - jquery 在同一页面中切换登录和注册

javascript - Jquery 鼠标悬停淡入/淡出(最佳实践)

javascript - 无需重新加载页面即可更改 YouTube 视频 ID

javascript - jQuery:根据数组中的值检查输入值

javascript - HTML仅显示具有特定值的表格数据

javascript - 简单的 Javascript 碰撞检测?

javascript - Google Maps V3 Circle 和我创建的 Circle 不匹配