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 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看