使用jQuery显示/隐藏父窗体的元素

时间:2014-01-08 12:55:47

标签: jquery css forms

我有一个表单提交按钮,直到用户选中复选框表示他们是人类时才会看到它(这不是我所知道的最佳实践,但我没有足够的控制权来放入Captcha)。

这是HTML:

<div class="row">
    <div class="large-5 columns large-centered center" 
         id="txtHuman" style="display:none">
    <input class="button" name="submitbutton" type="submit" value="Vote now!" />
    </div>
</div>

<div class="row">

    <div class="large-3 columns large-centered verification">
        <label for="isHumanSelected"><span></span></label>
        <input type="checkbox" id="isHumanSelected" style="margin-left:-9999px"/>
    </div>
</div>

这是jQuery:

$('#isHumanSelected').click(function() {
    $("#txtHuman").toggle(this.checked);
});

有效。但是,当表单提交按钮可见时,我想隐藏用于确定用户是否为人的复选框和标签。

我该怎么做?

4 个答案:

答案 0 :(得分:0)

<div id="PLACEANIDHERE" class="row">

  <div class="large-3 columns large-centered verification">
    <label for="isHumanSelected"><span></span></label>
    <input type="checkbox" id="isHumanSelected" style="margin-left:-9999px"/>
  </div>

</div>

切换容器的ID。标签和复选框都会同时显示/隐藏。

注意:隐藏一个复选框不会阻止机器人提交您的表单...他们重新创建表单提交,他们实际上并没有填写表单。

答案 1 :(得分:0)

$("#txtHuman").is(":checked"))
    $("#element").hide();
else
alert("not:Checked");

答案 2 :(得分:0)

怎么样

Live Demo

$(function() {
  $("#isHumanSelected").on("click",function() {
    $(this).parent().html($("#txtHuman").html());
  });
});

答案 3 :(得分:0)

您可以使用.parent()隐藏这些元素,试试这个:

$('#isHumanSelected').click(function() {
    $("#txtHuman").toggle(this.checked);
    $(this).parent('.verification').hide();
});

Demo Fiddle

相关问题