读书人

对象模型中对象的引述

发布时间: 2012-06-30 17:20:12 作者: rapoo

对象模型中对象的引用

通过name属性值引用

?

<form method="post" action="" name="form1"><input type="text" name="myname"></form> <script type="text/javascript">  <!--window.document.form1.myname.value='张三';  //-->  </script>

?

?通过数组下标引用

??

<form method="post" action="" name="form1"><input type="text" name="myname"><br><input type="text" name="myname2"></form> <script type="text/javascript">  <!--window.document.forms[0].elements[0].value='张三';window.document.forms[0].elements[1].value='李四';  //-->  </script>

?混合模式:

?

<form method="post" action="" name="form1"><input type="text" name="myname"><br><input type="text" name="myname2"><br><input type="text" name="myname3"></form> <script type="text/javascript">  <!--window.document.form1.myname.value='张三';window.document.forms[0].elements[1].value='李四';window.document.forms[0].myname3.value='myname3';  //-->  </script>

?在上述代码中window和document通常可以被省略

?


读书人网 >Web前端

热点推荐