js獲取單選按鈕的數(shù)據(jù)
更新時間:2006年11月27日 00:00:00 作者:
也許這是個很簡單的問題,可是在我學習程序的時候忽略了單選按鈕。導致對于他的數(shù)據(jù)傳遞方法的空缺。經過嗷嗷的幫助實現(xiàn)了下面關于年齡選擇的表單的數(shù)據(jù)獲取,僅僅在IE下測試成功了。先測試一下這個程序效果。
<form method="post" name="form1">
<label><input type="radio" name="radio" value="1-10 歲">1-10 歲</label>
<label><input type="radio" name="radio" value="11 歲">11 歲</label>
<label><input type="radio" name="radio" value="12-120 歲">12-120 歲</label>
<input type="button" onclick="ok()" value="測試選擇值">
</form>
下面是js獲取數(shù)據(jù)
<script language="javascript" type="text/javascript">
<!--
function ok()
{
var temp=document.getElementsByName("radio");
for (i=0;i<temp.length;i++){
//遍歷Radio
if(temp[i].checked)
{alert("你選擇了"+temp[i].value);
//獲取Radio的值
document.form2.textfield.value="你選擇了"+temp[i].value;
//傳遞給另外一個表單
}
}
}
-->
</script>
還想數(shù)據(jù)傳遞給另外一個表單
參考資料
js:http://www.blueidea.com/tech/web/2006/3567_8.asp
form:http://www.netvtm.com/w3s/html/html-forms.html
復制代碼 代碼如下:
<form method="post" name="form1">
<label><input type="radio" name="radio" value="1-10 歲">1-10 歲</label>
<label><input type="radio" name="radio" value="11 歲">11 歲</label>
<label><input type="radio" name="radio" value="12-120 歲">12-120 歲</label>
<input type="button" onclick="ok()" value="測試選擇值">
</form>
下面是js獲取數(shù)據(jù)
復制代碼 代碼如下:
<script language="javascript" type="text/javascript">
<!--
function ok()
{
var temp=document.getElementsByName("radio");
for (i=0;i<temp.length;i++){
//遍歷Radio
if(temp[i].checked)
{alert("你選擇了"+temp[i].value);
//獲取Radio的值
document.form2.textfield.value="你選擇了"+temp[i].value;
//傳遞給另外一個表單
}
}
}
-->
</script>
還想數(shù)據(jù)傳遞給另外一個表單
復制代碼 代碼如下:
<form method="post" name="form2">
<input type="text" name="textfield">
</form>
<input type="text" name="textfield">
</form>
參考資料
js:http://www.blueidea.com/tech/web/2006/3567_8.asp
form:http://www.netvtm.com/w3s/html/html-forms.html
相關文章
JavaScript實現(xiàn)復制粘貼剪切功能三種方法
這篇文章主要給大家介紹了關于JavaScript實現(xiàn)復制粘貼剪切功能的相關資料,在實際案例的操作過程中,不少人都會遇到這樣的開發(fā)需求,文中通過代碼將三種方法介紹的非常詳細,需要的朋友可以參考下2024-01-01