因程序设计需要,表单 name="keyboard[]" name中含有 []用JS取表单值的时候,需要用到document.searchform.keyboard[].value 取值,此中[]与数组冲突,请问各位老鸟怎样在不改变取值方式下 争取进行赋值?我知道表单取值还有一种方式:document.getElementsByName("keyboard");多谢各位了!

解决方案 »

  1.   

    document.searchform.elements["keyboard[]"].value = "xxxx";
      

  2.   

    我在Eclipse里用js库的自动提示,里面没有document.searchform这个方法诶,我把这个写入,结果FireFox报错,说:document.searchform未定义,LZ能告诉我这个用法到底怎么用吗?
    是这样吗?
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>测试该贴的问题2008-12-21</title>
    </head>
    <body>
    帖子:<a href="http://topic.csdn.net/u/20081220/18/9a790e8e-ad2c-4067-baf7-60dacc562c69.html">一个JS表单取值的问题,新手困扰多时!</a>
    <form action="#" id="ff" name="ff">
    <input name="keyboard[]" id="keyboard[]" type="text" value="abcdefg" />
    </form>
    <script>
    var formToGet = document.forms[0]; // 获取表单元素
    var eInput = formToGet.elements["keyboard[]"]; // 获得input元素
    alert(eInput.value); // 读取元素值
    eInput.value = "123456"; // 设置元素值
    alert(eInput.value);
    </script>
    </body>
    </html>
      

  3.   

    searchform 是form的名字
    <form action="#" id="searchform" name="searchform">