我想在此代码上添加 javascript 事件:
<p:dataTable id="tblQueues" var="q" value="#{gateBacking.listQueue}" filteredValue="#{gateBacking.filteredQueues}" rowKey="#{q.queid}"
selection="#{gateBacking.selectedQueue}" selectionMode="single" widgetVar="varQueues"
scrollable="true" scrollHeight="250">
...
<p:column headerText="License No" filterBy="#{q.fleet.licenseNo}" filterMatchMode="contains" >
#{q.fleet.licenseNo}
</p:column>
...
</p:dataTable>
如何添加onkeyup
过滤器?我试过这样:
<p:column headerText="License No" filterBy="#{q.fleet.licenseNo}" filterMatchMode="contains" onkeyup="formatLicense(this)">
但它不起作用。我怎样才能做到这一点?谢谢。
更新
我已经尝试过了,但它不起作用:
<p:column headerText="License No" filterBy="#{q.fleet.licenseNo}" filterMatchMode="contains" filterEvent="formatLicense(this)">
更新 2
<p:tabView id="tabViewGate">
<p:tab id="tabCheckOut" title="Out">
<h:form id="frmOut">
<p:dataTable id="tblQueues" var="q" value="#{gateBacking.listQueue}" filteredValue="#{gateBacking.filteredQueues}" rowKey="#{q.queid}"
selection="#{gateBacking.selectedQueue}" selectionMode="single" widgetVar="varQueues"
scrollable="true" scrollHeight="250">
...
<p:column id="colLicnu" headerText="License No" filterBy="#{q.fleet.licenseNo}" filterMatchMode="contains" >
#{q.fleet.licenseNo}
</p:column>
...
</p:dataTable>
<script type="text/javascript">
$(document).ready(function(){
$("#frmOut\\:tblQueues\\:colLicnu\\:filter").keyup(function(){
//alert("Test"); //--> I tried this too but it doesn't work
if (input.value.length > 1)
{
var num = '1234567890';
var str = input.value[input.value.length-1];
var str2 = input.value[input.value.length-2];
if (num.indexOf(str) >= 0) {
if (!(num.indexOf(str2) >= 0))
input.value = input.value.substring(0, input.value.length - 1) + " " + str;
}
else if (!(num.indexOf(str) >= 0)) {
if (num.indexOf(str2) >= 0)
input.value = input.value.substring(0, input.value.length - 1) + " " + str;
}
}
input.value = input.value.replace(" "," ").toUpperCase();
});
});
</script>
</h:form>
</p:tab>
</p:tab>