所需的腳本不工作所需要的編碼工作不
$("#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>
我現在需要它來使這個無線電領域所需要的時候顯示,而不是需要溫隱藏!當顯示和要求我需要一個錯誤信息發佈者:這個領域是必需的!
希望有人能幫助我!
你的[驗收](https://meta.stackexchange.com/a/5235/)記錄是可疑的。 –
我不認爲'#s_postby'會匹配'#s_postbyNUMBER'。 '$('input [name =「postby」])。each'可能更接近..雖然我沒有JS,PHP把我帶到了這裏。 – chris85
你需要養成[接受答案](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work)的習慣,它可以幫助你解決你的問題。您將獲得積分,其他人將被鼓勵幫助您。 –