w3c document.forms[0].fieldname equivalent

前端 未结 5 788
眼角桃花
眼角桃花 2021-01-14 03:35

I\'ve been using

document.forms[0].fieldname.value

to get values in javascript from a form, but I\'d like to use a name to reference the f

5条回答
  •  清酒与你
    2021-01-14 04:08

    Giving each element an unique id and using this id with the getElementById function is recommended:

    var value = document.getElementById('idofelement').value;
    

提交回复
热议问题