0

我有一个带贝宝按钮的跨度。我必须让这个贝宝按钮只有在用户确认 TOS 后才能按下。为此,我认为用 paypal 按钮覆盖另一个 div,其中未选中复选框、不透明度和 z-index。用户选中复选框,覆盖的 div 得到这样的 z-index,因此带有 paypal 按钮的 span 将在其上方并且可以按下。

我需要类似的东西

HTML

<div class="with_zindex">
    <input type="checkbox​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​">
<span class="here_is_paypal_button"></span>
</div>

CSS

.with_zindex{
background-color:#fafafa;
    opacity: .5;
    filter: alpha(opacity=50);
    -moz-opacity: .5;
z-index:1000;
}
.with_zindex + input[type=checkbox]:checked {
z-index:-1000;
}

但这对我不起作用(只有第一个格式,不能通过选中/取消选中复选框来改变)。

4

2 回答 2

0

我是这样弄的:

HTML:

<input class="Checkbox1" name="TOS" id="TOS" value="read" type="checkbox";"/>

JS

var $K2 = jQuery.noConflict();

 $K2(document).ready(function(){

//$K2('#TOS').attr('checked', false);
//$K2('input[type=image]').attr("class", "agbunchecked");
//$K2('input[type=image]').bind("click", giveAllert);

if(!$K2('#TOS').attr('checked')) //Existenzcheck
{
    $K2('input[type=image]').attr("class", "agbunchecked");
    $K2('input[type=image]').bind("click", giveAllert);
}

function giveAllert()
{
    alert("\Pleas check the checkbox!");
    return false;
}

$K2('#TOS').change(function(event){
    if(this.checked) 
    {
        $K2('input[type=image]').attr("class", "agbchecked");
        $K2('input[type=image]').unbind("click");
    }
    else
    {
        $K2('input[type=image]').attr("class", "agbunchecked");
        $K2('input[type=image]').bind("click", giveAllert)
    }
});

  });

CSS

.agbunchecked{
background-color:#fafafa;
opacity: .5;
filter: alpha(opacity=50);
-moz-opacity: .5;
}
于 2013-02-09T13:42:15.770 回答
0

建议

相反,您最初可以禁用 PayPal 按钮,然后在用户单击复选框后启用它。

HTML (jQuery 版本)

<input type="checkbox" name="terms" 
       onclick="$('#paypal').removeAttr('disabled');" />
<input type="image" name="paypal" id="paypal" disabled="disabled" />

HTML (JavaScript 版本)

<input type="checkbox" name="terms" 
       onclick="document.getElementById('paypal').removeAttribute('disabled');" />
<input type="image" name="paypal" id="paypal" disabled="disabled" />

否则,如果您坚持z-index

你需要position: relative;z-index工作付出。而且没有负数z-index

.with_zindex {
    background-color:#fafafa;
    opacity: .5;
    filter: alpha(opacity=50);
    -moz-opacity: .5;
    position: relative;
    z-index:1000;
}
.with_zindex + input[type=checkbox]:checked {
    position: relative;
    z-index: 0;
}

您需要的答案

HTML

<div class="with_zindex">
    <input type="Checkbox" name="TOS" value="read">
    <span class="catItemExtraFieldsValue">
        <img src="http://gutgeordnet.de/reise/images/epaypal_de.gif">
    </span>
</div>

CSS

.with_zindex {position: relative;}

.with_zindex input[type=checkbox] {
    background-color:#fafafa;
    filter: alpha(opacity=50);
    position: absolute;
    z-index: 50;
    top: 10px;
    left: -35px;
    width: 135px;
    text-align: right;
    vertical-align: top;
    cursor: pointer;
}

.with_zindex input[type=checkbox] + .catItemExtraFieldsValue {
    position: relative;
    opacity: .5;
    -moz-opacity: .5;
    z-index: 45;
}

.with_zindex input[type=checkbox]:after {
    content: 'I accept';
    font-size: 14px;
    vertical-align: top;
    line-height: 1em;
    font-weight: bold;
    font-family: tahoma;
}

.with_zindex input[type=checkbox]:checked {position: static; display: none;}

.with_zindex input[type=checkbox]:checked + .catItemExtraFieldsValue {
    position: static;
    background-color: transparent;
    opacity: 1;
    -moz-opacity: 1;
}

小提琴:http: //jsfiddle.net/praveenscience/35cQz/

于 2013-01-19T02:15:43.213 回答