跨浏览器问题:document.getElementById()。值在IE中不工作,但在Firefox中工作 [英] Cross Browser Issue : document.getElementById().value not working in IE but works in Firefox
问题描述
我有1个下拉框[年],2个文本框 [startDate,endDate]
,每当用户从下拉菜单中选择年份,然后文本框 startDate
应自动填充到 01/01 / + year
和 endDate
到 12/31 / + year
。下面提到的脚本在Firefox中可以正常工作,但在IE的getElementById('ff5')。值不工作,任何建议吗?
I have 1 dropdown box[year], 2 text box [startDate, endDate]
, whenever user select year from dropdown menu then text boxes startDate
should auto populate to 01/01/+year
and endDate
to 12/31/+year
. Below mentioned script works fine in Firefox but in IE getElementById('ff5').value is not working, any suggestions ?
我的脚本:
<script>
function autoPopulateDate(value, startDt,endDt){
document.getElementById(startDt).value='01/01/'+value;
document.getElementById(endDt).value='12/31/'+value;
}
</script>
HTML代码:
<tr>
<td>
<select onchange="autoPopulateDate(this.value,'ff5','ff6')" size="1" name="ff4" id="ff4"><option value="">-->select value<--</option><option value="2005">2005</option>
<option value="2006">2006</option>
<option value="2007">2007</option>
<option value="2008">2008</option>
<option value="ALL">ALL</option>
</select>
</td>
</tr>
<tr>
<td ><font class="rtabletext">Savings Start Date: </font></td>
<td >
<input type="text" value="" name="ff5" id="ff5" maxlength="50" size="10" class="text">
</td>
</tr>
<tr>
<td><font class="rtabletext">Savings End Date: </font></td>
<td>
<input type="text" value="" name="ff6" id="ff6" maxlength="50" size="10" class="text">
</td>
</tr>
推荐答案
IE [至少有些版本和呈现模式]您可以通过表单集合访问表单成员。
IE [at least some versions and rendering modes] wants you to access form members via the forms collection.
document.forms['someform'].elements['someelement'].value
或者,您可以使用一些ajax库(例如 http://www.asp.net/ajax ),并使用库元素检索方法,因为那些通常需要考虑浏览器兼容性的东西。 p>
Alternatively, you can use some ajax library (e.g. http://www.asp.net/ajax ) and use that libraries element retrieval method since those usually take browser compatibility stuff into account...
$get('element')
这篇关于跨浏览器问题:document.getElementById()。值在IE中不工作,但在Firefox中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!