ID在哪里像“pbg62d78562_2d4676_2d4b22_2d96b8_2d227d65ceaa9f_j_id1

Where does the ID like "pbG62d78562_2d4676_2d4b22_2d96b8_2d227d65ceaa9f_j_id1" come from?

本文关键字:2d96b8 2d227d65ceaa9f id1 2d4b22 2d4676 pbg62d78562 ID 在哪里      更新时间:2023-09-26

我正在使用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"strMol"一起出现,像这样:

<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在哪里?我怎样才能修好它?

我已经通过引用这个链接解决了这个问题。我怎样才能知道JSF组件的id,以便我可以在Javascript中使用

我只是把

 document.getElementById("#{strMol.clientId}").value =  editor.getMolfile();

这里我在标签

内添加了绑定
<h:inputHidden id="strMol" value="#{search.strMol}" binding="#{strMol}" />

既然我看到了<rich:panel>标记,我就假定您正在使用RichFaces,这是JSF的一种实现。该id由框架自动生成。你可以在这里读到一些背后的逻辑。

相关文章:
  • 没有找到相关文章