2013-09-28 36 views
0

我正在做一個項目,我需要兩個單選按鈕來進行日期選擇。一個單選按鈕需要系統日期和打印,但是當我選擇時另一個按鈕,我希望用戶能夠輸入日期(基本上我想要一個文本字段,當我點擊第二個單選按鈕時出現)。我是HTML編碼新手,所以請如果有人能幫助我。我讀了JavaScript和jQuery,但我看到werent的例子提供任何幫助。 我已經添加了單選按鈕使用單選按鈕觸發一個動作

<table border="1" width="100%"> 
<tr> 
<th> Date</th> 
</tr> 
<td> 
    Current date<input type="radio" name="zing" id="foo" checked/> 
    Add date<input type="radio" name="zing" id="bar"/></td> 
</table> 

請可能有人建議我的想法。

+0

請點擊 「編輯」,並添加你所擁有的這麼遠。 (你至少有單選按鈕的html,對吧?) – nnnnnn

回答

0
<table border="1" width="100%"> 
<tr> 
<th> Date</th> 
</tr> 
<td> 
    Current date<input type="radio" name="zing" id="foo" checked/> 
    Add date<input type="radio" name="zing" id="bar"/> 
<input type='text' id='txtDate' style='display:none'/> 
</td> 
</table> 

然後寫下如下腳本

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" ></script> 
<script> 
$(document).ready(function(){ 
    $("#bar").change(function(){ 
     $("#txtDate").show(); 
    }); 
$("#foo").change(function(){ 
     $("#txtDate").hide(); 
    }); 
}); 
</script> 
+0

感謝您的回覆,但您所說的jquery包含的是jqueryui.com的jquery.js文件嗎? –

+0

檢查我編輯的答案 – Patel

+0

非常感謝。我從jqueryui網站使用它。再次感謝。 –

0

試試這個

$(function(){ 
     $("input:radio:first").click(); 
    }); 
+0

它怎麼知道我選擇了哪個按鈕? –