如何在jQuery中触发p:selectOneButton的click事件

时间:2016-01-03 10:36:28

标签: javascript jquery jsf primefaces

我使用PF 5.3,使用JSF 2.2和jQuery of PrimeFaces 5.3(v1.11.3)

在客户端脚本中,我想触发p:selectOneButton的点击事件,所以如果人在浏览器中选择一个选项,它就会相同。

XHTML:

<h:form id="register_new_student" enctype="multipart/form-data" >
  <p:selectOneButton id="newStudentGender" value="#{newStudentPresentation.newPerson.gender}">
    <f:selectItem itemLabel="Male" itemValue="Male" />
    <f:selectItem itemLabel="Female" itemValue="Female" />
  </p:selectOneButton>
</h:form>

jQuery代码:

$(PrimeFaces.escapeClientId('register_new_student:newStudentGender:0')).trigger('click.selectOneButton');

但是这个jQuery代码没有用,有什么帮助吗?

2 个答案:

答案 0 :(得分:4)

试试这个:

<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <title>Options</title>
</head>

<body>
  <form action="Welcome" method="post">
    <h3>
Options
</h3>

    <input type="submit" value="View Personal Information" name="vpi">
    <br>
    <br>
    <input type="submit" value="View Expense Claims" name="vec">
    <br>
    <br>
    <input type="submit" value="View Payslips" name="vps">
    <br>
    <br>
    <input type="submit" value="Change Password" name="cp">
  </form>
</body>

</html>

使用$('#register_new_student\\:newStudentGender\\:0').click(); 转义函数将是这样的:

PrimeFaces

//选择器ID上的$(PrimeFaces.escapeClientId('register_new_student:newStudentGender:0')).click(); 是为了转义特殊字符\\:) 作为:州,请参阅http://api.jquery.com/category/selectors/

答案 1 :(得分:-1)

转到ID

&#13;
&#13;
function Logme(){
  
  $("#logSpan").html('clicked');
  
  
  }

$("#newStudentGender").trigger("click");
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button type="button" onclick="Logme()" id="newStudentGender">Click</button>
<span id="logSpan">Not clicked</span>
&#13;
&#13;
&#13;