derek5. 2015-07-07 07:33 采纳率: 100%
浏览 11

如何显示我的DIV?

I have a one dropdown menu so when I click on first item, I want to show DIV id=city3. and while I select another item, It will show DIV id=km automatically.

Problem : While I select first item, Div id=city3 is not visible and while I select another item, Div id=km is visible. So I want to show div id=city3 while I select first item.

Here is code.

$("#city_to").change(function()
{
    var id=$(this).val();
    var dataString = 'id='+ id;
    if(id==1)
    {
         $("#city3").show();
         $(".km").hide();
         $(".distance").val('');
         $(".allowance1").val('');
         $(".hq_allowance1").val('');
         $(".exhq_allowance1").val('');
         $(".os_allowance1").val('');
         $(".total_allowance").val('');
         $(".total").val('');
    }
    else
    {   
        $(".km").show();
        $("#city3").hide();

        $(".allowance").val('');
        $(".hq_allowance").val('');
        $(".exhq_allowance").val('');
        $(".os_allowance").val('');
        $(".total_allowance1").val('');
        $(".total").val('');

        $.ajax
        ({
            type: "POST",
            url: "ajax_pages/km.php",
            data: dataString,
            cache: false,
            success: function(html)
            {
                $(".km").html(html);
            } 
        });
    }
});
  • 写回答

1条回答 默认 最新

  • weixin_33709219 2015-07-07 07:51
    关注

    See my example so you can understand the working process.

    DEMO WORK

    <ul>
        <li class="abc" data-id="abc1">Home</li>
        <li class="abc" data-id="abc2">about</li>
        <li class="abc" data-id="abc3">serive</li>
        <li class="abc" data-id="abc4">contact</li>
    </ul>
    <div class="mm" id="abc1">Home worlld</div>
    <div class="mm" id="abc2">about worlld</div>
    <div class="mm" id="abc3">Service worlld</div>
    <div class="mm" id="abc4">Contact worlld</div>
    
    
    $(document).ready(function(){
        $(".mm").hide();
        $(".abc").click(function(){
              var mm = $(this).data("id");
                $(".mm").hide();
                $("#"+mm).show();
          });
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥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 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?