Jsf JQuery可以在页面加载时工作,但不能在页面加载后工作

Jsf JQuery可以在页面加载时工作,但不能在页面加载后工作,jsf,primefaces,Jsf,Primefaces,我在页面上有以下JQuery $("." + clazz).on("mousedown", function() { $(this).removeClass(clazz); $(this).addClass(clazzPressed); }); $("." + clazz).on("mouseup", function() { $(this).removeClass("clazzPressed"); $(this).addClass("clazz"); s

我在页面上有以下JQuery

$("." + clazz).on("mousedown", function() {
    $(this).removeClass(clazz);
    $(this).addClass(clazzPressed);
});
$("." + clazz).on("mouseup", function() {
    $(this).removeClass("clazzPressed");
    $(this).addClass("clazz");
    setCookie('cmpaid',$(this).attr('id'),1);
    divClickAction();
});
这对我来说很好。但是,我使用了一些AJax并在页面上更新了一些内容。一旦发生更新,此代码就不再有效

我怀疑这与它只在页面加载时被调用有关。一旦我更新了我的页面,新的东西就不知道了。有没有一种方法可以更新新的东西,使JQuery代码也包含在内

如果重要的话,这是通过Ajax更新的代码:

<h:panelGroup id="urlList"  >
                <script src="/resources/scripts/divClick.js"/>
            <script src="/resources/scripts/cookie.js"/>
                <ui:repeat id="urlRepeater" value="#{uRLManagerManagedBean.urls}" var="url" >
                    <div id="#{url.id_value.toString()}" class="divClick" style="margin-bottom: 10px;margin-left: 15px;">            
                        <div style="float:right;">
                            <p:outputLabel value="#{url.category.category}" /><br/>
                            <p:outputLabel value="Embedded" rendered="#{url.isEmbedded}"/>
                        </div>
                        <p:graphicImage value="#{streamedContentManagedBean.image}"  styleClass="urlImageSize" style="float: left;min-width: 25px;"> 
                            <f:param name="id" value="#{url.image.idAsString}" />
                        </p:graphicImage>
                        <h:panelGrid columns="1" >
                            <p:outputLabel value="#{url.name}" />
                            <p:outputLabel value="#{url.url}" rendered="#{not url.isEmbedded}" />  
                            <p:outputLabel value="#{url.embed.url}" rendered="#{url.isEmbedded}" /> 
                            <p:outputLabel value="#{url.type.toString(url.type)}" />
                            <h:outputText value="#{url.description}" escape="false"/> 
                        </h:panelGrid>
                    </div>
                </ui:repeat>

                <h:panelGroup layout="block" class="cardBody" style="margin-bottom: 10px;margin-left: 15px;padding:10px 10px 10px 10px;" rendered="#{empty uRLManagerManagedBean.urls}" >
                    <h:outputLabel value="No Urls" style="font-size: 25px;color: white;"/>
                </h:panelGroup>
            </h:panelGroup>



它是JSF,稍后会被一些代码更新。但是这个问题应该独立于此。

将javascript代码放在函数中,然后在页面加载时调用该函数

然后在页面上注册preRenderView事件的侦听器:

<f:metadata>
    <f:event type="preRenderView" listener="#{backingBean.preRenderViewListener}"/>
</f:metadata>

每次ajax请求后都会再次调用JavaScript。

能否将页面源代码与不起作用的jQuery脚本一起包含?或者这个脚本在/resources/scripts/divClick.js和/resources/scripts/cookie.js中?太棒了,让我试试看
public void preRenderViewListener()
{
    RequestContext.getCurrentInstance().execute("someJavaScriptFunction()");
}