在IE7文档模式(javascript)中以gn形式返回gsp下拉值

时间:2014-07-28 06:54:35

标签: javascript internet-explorer-7 nan

我正在通过javascript读取gsp页面下拉列表的索引值。除IE7文档模式外,js函数适用于所有浏览器。 js在IE7 DOCMODE中将值返回为NaN。试了半天多,但我找不到原因。任何帮助/建议真的很感激。复制js函数以供参考。

<script>var encodedMonthRange = new Array(); <g:each in="${ReportService.RangeList()}" var="mRange"> encodedMonthRange.push('${mRange?.encodeAsBase64()}'); function encodeParams(){ var index =Number(document.getElementById("monthRange").selectedIndex); alert("Index : " + index.toString()); var encodedVal = encodedMonthRange[index]; alert(encodedVal); document.getElementById("monthRangeEncoded").value = encodedVal; document.getElementById("historyOverview").submit(); } <script>

Html代码:

<div class="fl" style="padding-right:20px;"> <g:select id="monthRange" class="lstBox autocolor autoWidth" from="${ReportService.RangeList()}" valueMessagePrefix="filter" value="${params.monthRange}" onchange="encodeParams()" /> </div>

1 个答案:

答案 0 :(得分:0)

尝试添加.toString来电:

function encodeParams() {
    var index = document.getElementById("monthRange").selectedIndex;//index always number
    alert("Index : " + index.toString()); //add to String call
    var encodedVal = encodedMonthRange[index];
    alert(encodedVal);
    document.getElementById("monthRangeEncoded").value = encodedVal;
    document.getElementById("historyOverview").submit();
}

P.S。可能encodedMonthRange未定义?