2017-04-17 76 views
-1

所需的脚本不工作所需要的编码工作不

$("#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> 

我现在需要它来使这个无线电领域所需要的时候显示,而不是需要温隐藏!当显示和要求我需要一个错误信息发布者:这个领域是必需的!

希望有人能帮助我!

+3

你的[验收](https://meta.stackexchange.com/a/5235/)记录是可疑的。 –

+0

我不认为'#s_postby'会匹配'#s_postbyNUMBER'。 '$('input [name =“postby”])。each'可能更接近..虽然我没有JS,PHP把我带到了这里。 – chris85

+1

你需要养成[接受答案](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work)的习惯,它可以帮助你解决你的问题。您将获得积分,其他人将被鼓励帮助您。 –

回答