drxzpo70788179614 2012-10-09 07:48
浏览 35
已采纳

Jquery单选按钮未显示选定的div

I am using jquery to display div upon selection which is store to database

<script type="text/javascript"> 
    jQuery(document).ready(function(){

        jQuery("input[name$='advert_specifications[link_type]']").click(function(){

            var radio_value = jQuery(this).val();

            if(radio_value=='advert_page') {
                jQuery("#urlbox").hide('fast');
            }
            else if(radio_value=='external_link') {
                jQuery("#urlbox").show('fast');
            }
        });

        jQuery("#urlbox").hide();

    }); 
</script>



<div class="my_meta_control">

    <!--[advert link type group]-->
    <div class="left side clearfix">
        <label class="left sub_label"><input type="radio" value="advert_page" name="advert_specifications[link_type]"> Page Link</label>        
        <label class="left sub_label"><input type="radio" checked="checked" value="external_link" name="advert_specifications[link_type]"> External Link</label>
    </div>
    <!--[end of advert link type group]-->

    <div id="urlbox" style="display: none;">            
        <p class="sidebox clearform">
            <label>Advert External Link</label>     
            <input type="text" class="mydatepicker" value="" name="advert_specifications[advert_url]" id="advertdate">
        </p>
    </div>

</div>

It is working fine on click function but once I select external link radio and save to db than re open the post than #urlbox is always hide where it should be visible if external link radio button selected.

EDIT:

I tried this code and it does the same thing hiding # + test div on load

jQuery(document).ready(function() {
    jQuery("div.links").hide();
    jQuery("input[name$='advert_specifications[link_type]']").click(function() {
        var test = jQuery(this).val();
        jQuery("div.links").hide();
        jQuery("#" + test).show();
    });
});
  • 写回答

2条回答 默认 最新

  • duanfu1873 2012-10-09 08:25
    关注

    As per my understing in you main script you are hiding the main block. Although its not needed because you are alreadying saying display none in your markup.

    Please check the jsfiddle link

    DEMO

    http://jsfiddle.net/saorabhkr/DFPAX/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制