我花了很多时间,已经尝试了我能在网上找到的所有东西。没有任何效果!
作为标题,我需要在单击 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/