我正在使用JavaScript和Facelets页面,
这里是我的代码:
<h:head>
<script type="text/javascript">
function transfer() {
alert(editor.getMolfile());
document.getElementById("strMol").value = editor.getMolfile();
var newVal=document.getElementById("strMol").value;
alert("new val"+newVal);
}
</script>
</h:head>
<h:body>
<h:form id="searchMoleculeForm">
<h:inputHidden name="strMol" id="strMol" value="#{search.strMol}" />
<rich:panel >
<f:facet name="header">
Search The Molecule
</f:facet>
<center>
<div id="editor"></div>
</center>
<center>
<h:commandButton value="substructure" action="#{search.subStructure}" onclick="transfer();" />
<h:commandButton value="exact_similar" action="#{search.exactSearch}" onclick="transfer();" />
<h:commandButton value="pharmacophore" action="#{search.pharmacore}" onclick="transfer();" />
<h:commandButton value="shape" action="#{search.shapeSearch}" onclick="transfer();" />
</center>
</rich:panel>
</h:form>
<script type='text/JavaScript'>
var editor = chemwriter.loadEditor('editor');
</script>
</h:body>
它不起作用,当我查看源代码时,其他id带有id&#34; strMol&#34;像这样的东西:
<input id="pbG62d78562_2d4676_2d4b22_2d96b8_2d227d65ceaa9f_j_id1:searchMoleculeForm:strMol" type="hidden"
所以我把那个ID放在
中document.getElementById("pbG62d78562_2d4676_2d4b22_2d96b8_2d227d65ceaa9f_j_id1:searchMoleculeForm:strMol")
它开始起作用..
我的问题是,其他ID ID何在?我怎么能解决它?
答案 0 :(得分:0)
我已经通过参考此链接How can I know the id of a JSF component so I can use in Javascript
解决了这个问题我只是把
document.getElementById("#{strMol.clientId}").value = editor.getMolfile();
这里我在标签
中添加绑定<h:inputHidden id="strMol" value="#{search.strMol}" binding="#{strMol}" />
答案 1 :(得分:-1)