JavaScript获取表单元素值(一)

JavaScript获取表单元素值

以下四种方式均可获取,特别注意第三种,

    var a=document.getElementById("id1");
    var b=document.getElementsByName("na");

  1.     alert(id1.value);
  2.     alert(a.value);
  3.     alert(b[0].value);
  4.     alert(form1.na.value);
    <form name="form1" method="post" >
    <input type="text" name="na" id="id1" value="hahaha"><br>
    </form>

猜你喜欢

转载自blog.csdn.net/weixin_42565135/article/details/85297079
今日推荐