<html>
<head>
</head>
<body>
<form name="x" >
<input type="hidden" name="field" value="value">
<input name="model.username" type="hidden" value="1111">
</form>
<script language=javascript>
alert(document.forms[0].elements[1].value) ;
</script></body>
</html>

解决方案 »

  1.   

    alert(document.x.elements("model.username").value)
    or
    alert(document.getElementsByName("model.username")[0].value)
      

  2.   

    to  meizz(梅花雪) ,当只有一个字段名为"model.username"时,要用
    alert(document.x.elements("model.username").value)当大于1个字段名为"model.username"时要用
    alert(document.x.elements("model.username")[0].value)但是如何判断同名字段有几个呢?document.x.elements("model.username").length

    document.x.elements("model.username").length() 都没反应
      

  3.   

    document.getElementsByName("model.username").length;  // 大于1即个数不止一个.
      

  4.   

    但是,
    document.getElementsByName("model.username").length
    这样的取法是整个文档,而不是指定的 form 内的 model.username
    的元素个数而且,我还要在 form 内,当  model.username 打勾时相应的 model.password 也要打勾比如:<form name=form1>
      <input type=checkbox name="model.username" onclick=''
    <input type=checkbox name="model.password" onclick
    </form><form name=form2>
      <input type=checkbox name="model.username" onclick=''
    <input type=checkbox name="model.password" onclick
    </form>
      

  5.   

    写得有点不对,应是<form name=form1>
      <input type=checkbox name="model.username" onclick=''
    <input type=checkbox name="model.password" onclick  <input type=checkbox name="model.username" onclick=''
    <input type=checkbox name="model.password" onclick  <input type=checkbox name="model.username" onclick=''
    <input type=checkbox name="model.password" onclick
    </form><form name=form2>
      <input type=checkbox name="model.username" onclick=''
    <input type=checkbox name="model.password" onclick  <input type=checkbox name="model.username" onclick=''
    <input type=checkbox name="model.password" onclick  <input type=checkbox name="model.username" onclick=''
    <input type=checkbox name="model.password" onclick
    </form>
      

  6.   

    我试了一下, 用 document.form1.elements("model.username").length; 是可以正确得到这个表单下的同名表单元素个数的. 当同名元素个数只有一个时, 上面的这个 length 的值是等于 undefined 的.所以你可以这样做:
    var obj = document.form1.elements("model.username");
    if(obj.length == "undefined") alert(obj.type);
      

  7.   

    我用 if(obj.length == "undefined") 怎么也不会相等,不过,我用 obj.length > 0 代替了现在,如何才能取到 model.username 在 elements("model.username")中的位置呢?这样才能使用
    x.elements("model.password")[X].value =x.elements("model.username")[X].value
      

  8.   

    if(typeof(obj.length) == "undefined") 
    or
    if(obj.length == undefined) <= 这个有些地方好象不能支持这样写
      

  9.   

    http://community.csdn.net/Expert/topic/3857/3857742.xml?temp=.6153986
      

  10.   

    请来这
    http://community.csdn.net/Expert/topic/3857/3857742.xml?temp=.6153986如何才能确定一个表单内某个字段在多个同名字段数组中的位
    如果字段值不重复的话可以使用循环得到索引位置
    可是,如果允许字段值重复呢??