Freemarker在IE8上的渲染方式不同

时间:2012-09-06 15:32:30

标签: freemarker

我们有一个模板,用于记录行

<input type="${inputType}" name="${variableName}.code" id="${variable}.${vnum}.${answer.code}" class="checkbox" value="${answer.code}"
             [#nested/] [#if (answer.textLength > 0) && scripting]onchange="showOtherBox( this, '${variable}.[#if descriptionHack]${variableNumber}[#else]${vnum}[/#if].${answer.code}.description' )"[/#if]
             [#if showValues && (existing == answer.code)]checked="checked"[/#if]/>

在IE8上,它呈现为

<span class="field">
<INPUT id=responses.8.L class=checkbox value=L type=checkbox name="responses['8'].answers['L'].code"> 
<LABEL for=responses.8.L>Award(s) for special accomplishment or performance related to activity participation (please list)</LABEL> 
<TEXTAREA id=responses.8.L.description class=" visible" rows=4 cols=60 name="responses['8'].answers['L'].description"></TEXTAREA> 
</span>

并且在我们尝试的其他所有浏览器上,它都呈现为

<span class="field">
<input type="checkbox" name="responses['8'].answers['L'].code" id="responses.8.L" class="checkbox" value="L" onchange="showOtherBox( this, 'responses.8.L.description' )">
<label for="responses.8.L">Award(s) for special accomplishment or performance related to activity participation (please list)</label>
<textarea rows="4" cols="60" name="responses['8'].answers['L'].description" id="responses.8.L.description" class="visible" classname="visible"></textarea>
</span>

区别在于FTL脚本中的if语句

[#if (answer.textLength > 0) && scripting]

除了IE之外的所有内容都是如此。在IE8中它出于某种原因是假的,因此它不会在输入标记上放置OnChange javascript事件。以前有人见过这样的事吗?我们正在使用Freemarker 2.3.9

更新,如果我打开IE8的兼容模式,它会有用。但不完全一样。当我这样做时,onchange事件不会触发,直到复选框失去焦点。这与其他一切都非常不同。有没有一个快速解决这个问题没有太多麻烦?我想我可以放一些东西,如果ie8,插入onclick而不是onchange。这可能有用,但我需要客户授权来修复它。

1 个答案:

答案 0 :(得分:0)

由于FreeMarker仅在服务器上运行,因此不会直接受浏览器的影响。你应该在<!-- answer.textLength = ${answer.textLength}, scripting = ${scripting?string} -->之前添加[#if]之类的内容,以便你可以看到条件失败的原因,然后找出问题变量的值来自哪里,因为通常它不是FreeMarker设定它。 (Bare-bone FreeMarker甚至无法检测浏览器类型。)