如何使用jQuery激活按钮

How to activate a button with jQuery?

本文关键字:按钮 激活 jQuery 何使用      更新时间:2023-09-26

一旦用户单击"我同意…"文本的checkbox,我将尝试显示Next-Button。我尝试了()toggleshow/hide,但都无法正常工作。知道怎么解决这个问题吗?

jQuery

<script>
$(document).ready(function(){
  $("#i_agree_check").click(function(){
    $("next_2_btn_info").hide();
  });
  $("#i_agree_check").click(function(){
    $("next_2_btn_info").show();
  });
});
</script>

HTML

    <div class="checkbox_agree show"><input type="checkbox" id="i_agree_check"</><?php echo $lang ['i_agree']; ?></div>
    <div class="edit_btn"> <!-- Not active placeholder -->
        <a href="#" title="<?php echo $lang ['complete_step']; ?>"><?php echo $lang ['next']; ?></a>
    </div>
    <div class="next_2_btn_info" id="next_2_btn_info">
        <a href="order_banner_2.php"><?php echo $lang ['next']; ?></a>
    </div>  

试试这个(更新):

$("#next_2_btn_info").hide();
$("#i_agree_check").click(function(){
    $("#next_2_btn_info").toggle();
  });
$("next_2_btn_info").hide(); //Change
$("#next_2_btn_info").hide();

你能试试吗?你需要在选择器元素之前添加#.,比如$("#next_2_btn_info")

    $(function(){
      $("#i_agree_check").click(function(){
             $("#next_2_btn_info").toggle();     
      });
    });

您正在用复选框注册两个相互矛盾的click事件,并且您没有使用按钮的id。试试这个:

$(document).ready(function(){
  $("#i_agree_check").click(function(){
         $("#next_2_btn_info").toggle();     
  });
});

注意它是#next_2_btn_info而不是next_2_btn_info。此外,.toggle()根据对象的当前状态显示/隐藏。

您正在$("#i_agree_check")上连续两次设置单击处理程序。尝试设置一个单击处理程序,并测试复选框的值,以确定是否已选中该复选框。

$('#i_agree_check').click(function(){
 if($("#i_agree_check").is(':checked')) { 
  $('next_2_btn_info').show();
 } else {
  $('next_2_btn_info').hide();
 }
}