我的javascript函数存在问题:
JS代码:
function ouvrirPopupAvecImprEcran(){
var name= document.getElementById("myForm:currentName").value;
var code= document.getElementById("myForm:currentCode").value;
...
}
此功能适用于Chrome,但是当我尝试使用firefox时,函数getElementById会返回“undefined”。我查看了我生成的HTML输出,看看id是否已经存在,但它们没有。
生成的HTML输出:
<form id="myForm" name="myForm" method="post" action="/MyProject/p/handleTest.jsf" enctype="application/x-www-form-urlencoded">
<select id="myForm:currentName" size="1" name="myForm:currentName">
...
</select>
...
<input name="myForm:j_idt556" value="Print" onclick="return ouvrirPopupAvecImprEcran();" type="submit">
...
<input id="myForm:currentCode" name="myForm:currentCode" value="Hey" type="hidden">
</form>
我不明白为什么这段代码在Firefox中不起作用。
请问你能帮帮我吗?
谢谢。
答案 0 :(得分:-1)
可能是Firefox在ID字符串中出现了冒号问题。你可以尝试将\\
放在它前面来逃避冒号吗?
答案 1 :(得分:-1)
将“:”更改为“_”
in html
在javascript中
var name = document.getElementById(“myForm_currentName”)。value;
试试这个