我有一个包含3列的primefaces数据表:vote3,vote2和vote1,每列包含一个按钮,在页面加载时只有投票3列可见,我想要的是当我点击列vote3中的按钮时,列消失,列vote2出现,然后与列vote2和vote1相同,我为此写了一个jquery脚本,结果是:在页面加载时只有投票3列是可见的,但是当我点击按钮vote3时,列不会消失,列vote2也不会出现。 我的数据表
<h:form id="form">
<p:dataTable value="#{projectsMB.projects}" var="p" border="1">
<p:column>
<f:facet name="header">
<h:outputText value="id" />
</f:facet>
<h:outputText value="#{p.id}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="NAME" />
</f:facet>
<h:outputText value="#{p.name}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="GOAL" />
</f:facet>
<h:outputText value="#{p.objective}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="DESCRIPTION" />
</f:facet>
<h:outputText value="#{p.description}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="ACTION" />
</f:facet>
<h:commandButton actionListener="#{projectsMB.delete(p)}" value="del" />
</p:column>
<p:column id="vote3">
<f:facet name="header">
<h:outputText value="Vote" />
</f:facet>
<p:commandButton actionListener="#{projectsMB.vote3()}" value="3 points" icon="ui-icon-search" styleClass="voteButton" >
<f:setPropertyActionListener value="#{p}" target="#{projectsMB.project}" />
</p:commandButton>
</p:column>
<p:column id="vote2" style="display:none">
<f:facet name="header">
<h:outputText value="Vote" />
</f:facet>
<p:commandButton actionListener="#{projectsMB.vote2()}" value="2 points" icon="ui-icon-search" styleClass="voteButton" >
<f:setPropertyActionListener value="#{p}" target="#{projectsMB.project}" />
</p:commandButton>
</p:column>
<p:column id="vote1" style="display:none">
<f:facet name="header">
<h:outputText value="Vote" />
</f:facet>
<p:commandButton actionListener="#{projectsMB.vote1()}" value="1 point" icon="ui-icon-search" styleClass="voteButton" >
<f:setPropertyActionListener value="#{p}" target="#{projectsMB.project}" />
</p:commandButton>
</p:column>
</p:dataTable>
<h:commandButton actionListener="#{projectsMB.doNew()}" value="new" />
</h:form>
我的剧本
<h:head>
<script>
$(function() {
var c=0;
$(".voteButton").click(function () {
if(c==0)
{$("#vote3").hide( );
$("#vote2").show();
c++;
}
if(c==1)
{$("#vote2").hide( );
$("#vote1").show();
c++;
} });});
</script>
</h:head>