日期:2014-05-18  浏览次数:21333 次

★★★求助JAVASCRIPT高手一个棘手的问题!谢谢!★★★
<form   name= "myForm "   action= " ">
      <input   type= "student.name "/>
      <input   type= "submit "/>
</form>

这是个简单的表单,下面是使用脚本对这个form访问:
<script   language= "javascript ">
        window.alert(document.myForm.student.name);
</script>

上面模拟了一个我遇到的问题,就是HTML中标签的name属性如果有 ". ",例如上面的name= "student.name ",就会使脚本无法正确使用,原因很简单,因为JAVASCRIPT也是面向对象的,允许使用“对象实例.属性”访问HTML标签,所以student.name会报出一个“name属性未定义的脚本错误”,也就是说JAVASCRIPT把student.name没有当成一个独立的文本框的名字,我想问问这个问题应该怎么解决啊?

因为我使用的是WebWork模型驱动模式,表单中的name属性必须是   student.name   这样的形式,请大家帮忙怎么解决一下哦!最好是在 <input   type= "student.name "/> 这个地方想办法!谢谢啊!

------解决方案--------------------
首先,你的from有问题
<input name= "student.name "/>

window.alert(document.myForm[ 'student.name ']);
------解决方案--------------------
window.alert(document.myForm[ 'student.name ']);

就这个,给分吧