讀取表單的值
function showFormValue(){
var form = document.forms["myform"];
alert(form.name.value);
alert(form.xb.value);
//debugger;斷點(diǎn)檢查
var arr = form.ah;
var sel = [];
for(var i=0;i<arr.length;i++){
if (arr[i].checked==true){
sel.push(arr[i].value);
}
}
alert(sel.join(","));
var jn = form.jn.value;
alert(jn);
var grjj = form.grjj.value;
alert(grjj);
var hid = form.hid.value;
alert(hid);
alert(document.getElementById("xm".value));
}
function setFormValue(){
var form = document.forms["myform"];
form.name.value = "林";
form.jn.value = 2;
form.grjj.value = "請(qǐng)輸入個(gè)人簡(jiǎn)介";
form.xb.value = 2;
var ahs = form.ah;
var len = ahs.length;
for (var i=0;i<len;i++){
if(i==0){
continue;
}
if(i==len-1){
break;
}
ahs[i].checked = true;
}
}
給按鈕注冊(cè)一個(gè)事件
window.onload = function(){
//獲取按鈕對(duì)象
var subBtn = document.getElementById("subBtn");
subBtn.onclick = showFormValue;
setFormValue();
}