我想制作复选框,以便即使有人试图ticked
他们也应该untick
。我的HTML是;
<fieldset class="trow2">
<legend><strong>{$lang->account_prefs}</strong></legend>
<table cellspacing="0" cellpadding="{$theme['tablespace']}" width="100%">
<tr>
<td valign="top" width="1"><input type="checkbox" class="checkbox" name="allownotices" id="allownotices" value="1" {$allownoticescheck} /></td>
<td valign="top"><span class="smalltext"><label for="allownotices">{$lang->allow_notices}</label></span></td>
</tr>
<tr>
<td valign="top" width="1"><input type="checkbox" class="checkbox" name="receivepms" id="receivepms" value="1" {$receivepmscheck} /></td>
<td valign="top"><span class="smalltext"><label for="receivepms">{$lang->receive_pms}</label></span></td>
</tr>
<tr>
<td valign="top" width="1"><input type="checkbox" class="checkbox" name="pmnotice" id="pmnotice" value="1"{$pmnoticecheck} /></td>
<td valign="top"><span class="smalltext"><label for="pmnotice">{$lang->pm_notice}</label></span></td>
</tr>
<tr>
<td valign="top" width="1"><input type="checkbox" class="checkbox" name="emailpmnotify" id="emailpmnotify" value="1" checked="checked" {$emailpmnotifycheck} /></td>
<td valign="top"><span class="smalltext"><label for="emailpmnotify">{$lang->email_notify_newpm}</label></span></td>
</tr>
<tr>
<td colspan="2"><span class="smalltext"><label for="subscriptionmethod">{$lang->subscription_method}</label></span></td>
</tr>
<tr>
<td colspan="2">
<select name="subscriptionmethod" id="subscriptionmethod">
<option value="2" {$instant_email_subscribe_selected}>{$lang->instant_email_subscribe}</option>
</select>
</td>
</tr>
</table>
</fieldset>
如果我尝试在DISABLED
标记中使用input
属性,则该值无法通过该脚本,另一方面,我不想在HIDDEN
属性中使用input
属性{{1}}因为它隐藏了我不想做的复选框,我想显示复选框,默认勾选,但用户不应该取消它们。
如果有人使用jQuery为我提供解决方案,我感到很满意。
请帮忙!
答案 0 :(得分:2)
尝试使用所有复选框:
<input type="checkbox" checked="checked" onclick="return false" />
答案 1 :(得分:0)
由于您愿意使用jQuery,请尝试:
$('input[checked=checked]').click(function() {return false;});
这会阻止点击在输入上注册。您可能需要在标签上添加类似的处理程序,因为浏览器也会通过点击更改输入状态。
但是,这仍然是一个问题,这是否真的是最好的方法。请参阅此处的讨论:Can HTML checkboxes be set to readonly?
答案 2 :(得分:0)
当用户尝试将复选框值更改为false时,会触发change
事件,您始终可以使用prop
$("input[type=checkbox]").change(function(){
$(this).prop("checked",true);
})