【问题标题】:Changing the z-index of a div when a function is called?调用函数时更改 div 的 z-index?
【发布时间】:2012-03-14 00:20:33
【问题描述】:

当 createCustomerCard('CUST_0') 被调用时,它会打开下面的第一张订单卡

<div id="CUST_0" class="widget ui-dialog ui-widget ui-widget-content ui-corner-all ui-draggable" style="width: 500px; height: auto; font-size: 11px; display: block; left: 29px; top: 156px; z-index: 1013; ">

z-index 为 1013,但如果您尝试调用相同的函数,它要么不绘制客户卡,要么不增加 z-index,因为如果创建了 CUST_01 卡,则 z-index 高于 z-index CUST_0。有没有办法在调用函数时将 div id 的 z-index 增加 1?

CUST_2 示例如下

<div id="CUST_2" class="widget ui-dialog ui-widget ui-widget-content ui-corner-all ui-draggable" style="width: 500px; height: auto; font-size: 11px; display: block; z-index: 1014; left: 319px; top: 162px; ">

【问题讨论】:

    标签: javascript jquery html


    【解决方案1】:

    添加到样式position:relative 说@Mr Lister 或position:absolute

    <div id="CUST_0" class="widget ui-dialog ui-widget ui-widget-content ui-corner-all ui-draggable" style="width: 500px; height: auto; font-size: 11px; display: block; left: 29px; top: 156px; position:relative;z-index: 1013; ">
    

    并在调用函数的位置添加 jQuery:

    $('#CUST_N').css("z-index", $('#CUST_N').css("z-index")+1);
    

    【讨论】:

      【解决方案2】:

      除了static 之外,该div 是否还有position?只有定位元素才能使用 z-index。所以给它position:relative,它可能会起作用。

      对了,为什么是z-index:1013?这个号码有什么特别之处?

      【讨论】:

      • 从z-index的起始值递增:999;从某个地方:)
      【解决方案3】:

      这应该将 z-index 增加 1:

      $('#CUST_N').css("z-index", "+=1");
      

      【讨论】:

        猜你喜欢
        • 2023-03-21
        • 2015-07-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多