首页 > 解决方案 > javascript函数禁用div中的变量发送,如何停止

问题描述

$('[data-toggle="wizard-radio"]').click(function() {
    wizard = $(this).closest('.wizard-card');
    wizard.find('[data-toggle="wizard-radio"]').removeClass('active');
    $(this).addClass('active');
    $(wizard).find('[type="checkbox"]').removeAttr('checked');
    $(this).find('[type="checkbox"]').attr('checked','true');
})

此代码以某种方式禁止发送变量,因此我可以$_POST在服务器端使用数组获取它

任何想法如何在提交时激活它以发送

标签: javascriptjquerycss

解决方案


这两条线需要帮助

$(wizard).find('[type="checkbox"]').removeAttr('checked');
$(this).find('[type="checkbox"]').attr('checked','true');

复选框的正确方法是.prop('checked', true/false)

我还删除了该hidden属性,因为它使事物不可见。你需要那个吗?

$('[data-toggle="wizard-radio"]').click(function() {
  wizard = $(this).closest('.wizard-card');
  wizard.find('[data-toggle="wizard-radio"]').removeClass('active');
  $(this).addClass('active');
  $(wizard).find('[type="checkbox"]').prop('checked', false);
  $(this).find('[type="checkbox"]').prop('checked', true);
})
.active {
  color: #f00;
}

.card-checkboxes {
  display: inline-block;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class='wizard-card'>
  <div class="choice" data-toggle="wizard-radio">
    <div class=" btn-next " hidden>
      <input type="checkbox" name="Great" value="Great">
      <div class="card card-checkboxes card-hover-effect">
        <i class="ti-face-smile"></i>
        <p style="font-weight: bold;">Great</p>
      </div>
    </div>
  </div>

  <div class="choice" data-toggle="wizard-radio">
    <div class=" btn-next ">
      <input type="checkbox" name="soso" value="Soso">
      <div class="card card-checkboxes card-hover-effect">
        <i class="ti-face-smile"></i>
        <p style="font-weight: bold;">So-so</p>
      </div>
    </div>
  </div>
</div>


推荐阅读