【问题标题】:required codes in script are not working [duplicate]脚本中所需的代码不起作用[重复]
【发布时间】:2017-09-13 10:40:03
【问题描述】:

脚本中的要求不起作用

$("#s_postby").attr('required', false); // put the id of the input field that you whant required
$("#s_postby").attr('required', true); // put the id of the input field that you whant required

我在项目帖子上的 osclass 主题中创建了一些无线电字段!

    <div id="postby" class="property-ads-100">
      <label>
        <span class="required_fields">*</span>
        <?php _e('Posted By', 'ctg_housing'); ?>
      </label>
      <div class="item-post-postby-checkbox columns-0">
        <input  type="radio" name="s_postby" value="owner" id="s_postby0" <?php if(isset($housing['s_postby']) && $housing['s_postby'] =='owner') { echo 'checked="checked"'; }; ?>>
        <label for="s_postby0">
          <?php _e('Owner', 'ctg_housing'); ?>
        </label>
      </div>
      <div class="item-post-postby-checkbox columns-0">
        <input type="radio" name="s_postby" value="agent" id="s_postby1" <?php if(isset($housing['s_postby']) && $housing['s_postby'] =='agent') { echo 'checked="checked"'; }; ?>>
        <label for="s_postby1">
          <?php _e('Agent', 'ctg_housing'); ?>
        </label>
      </div>
      <div class="item-post-postby-checkbox columns-0">
        <input type="radio" name="s_postby" value="broker" id="s_postby2" <?php if(isset($housing['s_postby']) && $housing['s_postby'] =='broker') { echo 'checked="checked"'; }; ?>>
        <label for="s_postby2">
          <?php _e('Broker', 'ctg_housing'); ?>
        </label>
      </div>
      <div class="item-post-postby-checkbox columns-0">
        <input type="radio" name="s_postby" value="agency" id="s_postby3" <?php if(isset($housing['s_postby']) && $housing['s_postby'] =='agency') { echo 'checked="checked"'; }; ?>>
        <label for="s_postby3">
          <?php _e('Agency', 'ctg_housing'); ?>
        </label>
      </div>
    </div>

我在某些类别上隐藏了这个(脚本中要求的不起作用!!)为什么??

<script type="text/javascript">
$('#catId').change(function(){
    if( $('#catId').val() == "28" || $('#catId').val() == "29" || 
$('#catId').val() == "30" || $('#catId').val() == "31")
    {
        $("#postby").hide();  // change Posted By with ID you give to the div
    $("#s_postby").attr('required', false); // put the id of the input field that you whant required
    }else
    {
         $("#postby").show(); // change Posted By with ID you give to the div
    $("#s_postby").attr('required', true); // put the id of the input field that you whant required
    }
});
</script> 

我现在需要它来使这个广播字段在显示时需要,而不是在隐藏时需要!当显示和需要时,我需要一个错误消息发布者:此字段是必需的!

希望有人可以帮助我!

【问题讨论】:

  • 您的acceptance 记录有问题。
  • 我认为#s_postby 不会匹配#s_postbyNUMBER。 $('input[name="postby"]).each 可能更接近.. 虽然我不太会 JS,但 PHP 把我带到了这里。
  • 您需要养成accepting answers 的习惯,它可以帮助您解决问题。您将获得积分,并鼓励其他人帮助您。
  • 谢谢,我会试试这个,让你知道是否工作

标签: javascript php html


【解决方案1】:

【讨论】:

  • “哦,没有人在乎你是女学生。” - 答案不应该出现在答案中,我在问题中删掉了那个绒毛.
  • @Fred-ii- 但我是对的
  • 这是一个最好保留给自己的评论;-)
猜你喜欢
  • 1970-01-01
  • 2017-05-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-28
  • 2019-01-07
  • 1970-01-01
  • 2023-03-06
相关资源
最近更新 更多