2014-02-19 43 views
0

我在這裏有一個代碼,用於禁用表單上的收音機,並在計時器到期後立即關注提交按鈕。但是這段代碼似乎不起作用。你能告訴我我的代碼有什麼問題,或者如果你有其他選擇嗎?我使用jQuery插件timeTo作爲我的定時器..禁用輸入標籤並專注於提交按鈕

<script type="text/javascript"> 
$(document).ready(function() { 
$('#countdown').timeTo(5000, disablefocus(); 
    }); 
}); 

function disablefocus(){ 
$(document).ready(function() { 
$('input[type=radio]').attr('disabled', true); 
$('#submitWidget').focus(); 
}); 
</script> 

---->

<div id='countdown'></div> 
<form> 
<input type='radio' name='radio1' value='father'> 
<input type = 'submit' id ='submitwidget' value='submit'/> 
</form> 
+0

任何改進? –

+0

抱歉,遲到回覆。是的,它現在正在工作。但是你能幫我提供一些關於CSS的知識嗎?我想將背景更改爲灰色,並將一些小動畫更改爲按鈕旁邊,表示他需要單擊它。 ''你必須點擊我吧!'' – Nixxhalle

+0

我試過了,但沒有任何反應 '$(document).ready(function(){ $('倒計時 ')timeTo(20,函數(){disablefocus();}); 功能disablefocus(){ VAR消息=的document.getElementById(' #confirmMessage'); VAR goodColor = 「#66cc66」; $('input [type = radio]')。attr('disabled',true); $('#submitWidget')。focus(); message.style.color = goodColor; message.innerHTML =「現在按下我!「 } });' – Nixxhalle

回答

0

你添加額外的花括號爲timeTo功能和錯過disableFocus功能關閉的大括號。

$(document).ready(function() { 

$('#countdown').timeTo(5000, disablefocus); 

function disablefocus(){ 

$('input[type=radio]').attr('disabled', true); 
$('#submitWidget').focus(); 

} 

}); 

或另一種方式

$('#countdown').timeTo(5000, function() { disablefocus(); }); 
+0

我需要顯示時鐘滴答,這就是爲什麼我使用插件。而且,這個像單選按鈕這樣的小動畫會變成灰色,以通知用戶它已被禁用? – Nixxhalle

+0

$('#countdown')。timeTo(5000,disablefocus);更換線路並檢查 –

+0

您爲該場景放置了額外的一個花括號。 –

0

使用下面的代碼,它一定會幫助你

$(document).ready(function() { 
     $('#countdown').timeTo(5000, function(){ 
      disablefocus(); 
     }   
     }); 
    }); 

任何幫助你問,我也面臨類似的問題

0
$(document).ready(function() { 

$('#countdown').timeTo(20, function() { 

      disablefocus(); 

}); 

function disablefocus(){ 

    var message = $('#confirmMessage'); 
    var goodColor = "#66cc66"; 
    $('input[type=radio]').attr('disabled', true); 
    $('#submitWidget').focus(); 
    message.css("color" , goodColor); 
    message.html("Press me now!"); 

    } 
}); 
+0

你能告訴我什麼是timeTo插件的使用。語法是正確的? –