2010-07-19 56 views
1

這很奇怪,因爲我在IE中只有1個錯誤:'sTime是未定義的'。 sTime是表單中許多輸入元素之一的ID。在Chrome和FF中一切正常。這裏有一個鏈接代碼:無法訪問IE中的表單元素,因爲它'未定義'。在FF和Chrome中可以正常工作

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' /> 

感謝您的幫助!

回答

3
  • 嘗試把JavaScript的入onsubmit事件,而不是action

  • 地址形式的元件少含糊在JS,例如使用this.elements.sTime。可能是元素名稱在文檔的其他地方使用。

+0

使用的onsubmit而不是行動似乎允許IE訪問輸入元素。現在即不喜歡我用來格式化日期字符串的正則表達式...任何想法可能會導致這種情況? – 2010-07-19 10:23:28

+0

@culov nope,對不起。也許值得一個單獨的問題。 – Unicron 2010-07-19 12:45:46

0

表單行爲中的Javascript應該可以正常工作。 也許你應該使用的sTime.value如下:

document.forms[0].sTime.value 

當然,這意味着,這種形式在頁面的第一(否則你必須改變...forms[0]......forms['formname']......forms[<form index>]...

相關問題