我想在jQuery中編寫一個函數,當用戶點擊一個複選框時,textfield-2變爲enabeled並且需要並且textfield-1被禁用。如果未選中複選框,則textfield-2將被禁用且不是必需的,並且textfield-1將被啓用。使用jQuery啓用/禁用textfield通過點擊複選框黑洞
所以就像這兩個文本框之間的切換。表格是某事像這樣:
<form id="link" name="link" action="post">
<input type="checkbox" name="url_type" id="url_type" >
<input type="text" name="textfield1" id="textfield1">
<input type="text" name="textfield2" id="textfield2" disable="disable">
<input type="submit" name="send" value="send">
</form>
而jQuery代碼看起來是這樣的:
<script type="text/javascript">
$('#url_type').on('change',function(){
var checked=$('#url_type').is(':checked');
if(checked==true)
{
$('#textfield1').attr('disabled',true);
$('#textfield2').attr('disabled',false);
} else {
$('#textfield1').attr('disabled',false);
$('#textfield2').attr('disabled',true);
}
});
</script>
我的問題是,在CakePHP中,當我創建一個新的連接,如果沒有選中複選框工作正常,但如果我檢查複選框(意味着textfield2變爲啓用並禁用textfield1),它將生成如下所示的錯誤:
請求已被黑洞錯誤:請求的地址未找到這臺服務器。
我不知道衝突在哪裏,或者是什麼導致了這個錯誤!
它可能與['SecurityComponent'](http://book.cakephp.org/2.0/en/core-libraries/components/security-component.html#security)有關。檢查['csrf'](http://book.cakephp.org/2.0/en/core-libraries/components/security-component.html#csrf-configuration)部分 – noslone