繁体   English   中英

IE中的表单元素“未定义”,因此无法访问。 在FF和Chrome中可以正常运行

[英]Can't access form element in IE because it 'is undefined'. Works ok in FF and Chrome

这很奇怪,因为我在IE中仅收到1个错误:“ sTime未定义”。 sTime是表单中许多输入元素之一的ID。 在Chrome和FF中一切正常。 这是代码的链接:

http://la.truxmap.com/sched.html

和表单html:

<form id="addNewTruck" class='updateschedule' action="javascript:sub(sTime.value, eTime.value, lat.value, lng.value, street.value);"> 

    <b style="color:green;">Opening at: </b> 
        <input id="sTime" name="sTime" title="Opening time" value="Click to set opening time" class="datetimepicker"/> 

    <b style="color:red;">Closing at: </b> 
        <input id="eTime" name= "eTime" title="Closing time" value="Click to set closing time" class="datetimepicker"/> 

    <b style="color:blue;">Address: </b> 
        <input type='text' name='street' id='street' class='text street' autocomplete='off'/> 
        <input id='submit' class='submit' style="cursor: pointer; cursor: hand;" type="submit" value='Add new stop'/> 
    <div id='suggests' class='auto_complete' style='display:none'></div> 
        <input type='hidden' name='lat' id='lat'/> 
        <input type='hidden' name='lng' id='lng'/> 
        <input type='hidden' value='CA' name='state' id='state' class='text state' /> 

谢谢你的帮助!

  • 尝试将JavaScript置于onsubmit事件而非action

  • 在JS中不太明确地处理表单元素,例如使用this.elements.sTime 元素名称可能在文档的其他地方使用。

表单中的Javascript应该可以正常运行。 也许您应该使用以下内容代替sTime.value

document.forms[0].sTime.value

当然,这意味着此表单是页面中的第一个表单(否则,您必须将...forms[0]...更改为...forms['formname']......forms[<form index>]...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM