日期:2014-05-16 浏览次数:20334 次
<form> <input name="textName1" type="text" id="textName1" /> <input name="textName2" type="text" id="textName2" /> ....(n个text).... <input type="radio" name="r1"value="测试1" checked>测试1<br> <input type="radio" name="r1"value="测试2" checked>测试2<br> ....(n对radio).... <input type="button" name="Submit" value="Submit" onclick=save() /> </form>
function save() { var ar_text = [], ar_radio = []; var obj = document.getElementsByTagName('form')[0].getElementsByTagName('input'); for (var i = 0; i < obj.length; i ++) { if (obj[i].type == 'text' && obj[i].value.length > 0) ar_text.push(obj[i].value); if (obj[i].type == 'radio' && obj[i].checked) ar_radio.push(obj[i].value); } alert(ar_text); alert(ar_radio); return [ar_text, ar_radio]; }