ฉันต้องการตั้งค่าสถานะที่ตรวจสอบบน p:selectOneRadio โดยใช้ javascript
ฉันจัดการได้ แต่ใช้งานได้เฉพาะกับองค์ประกอบแรกในรายการ selectOneRadio นี่คือรหัส
<h:form id="formID">
<p:outputPanel id="customPanel" style="margin-bottom:10px">
<p:selectOneRadio id="customRadio" value="#{radioView.color}" layout="custom">
<f:selectItem itemLabel="Red" itemValue="Red" />
<f:selectItem itemLabel="Green" itemValue="Green" />
<f:selectItem itemLabel="Blue" itemValue="Blue" />
</p:selectOneRadio>
<h:panelGrid columns="2" cellpadding="5" border="1">
<p:radioButton id="opt1" for="customRadio" itemIndex="0" />
<h:outputLabel for="opt1" value="Red" />
<p:radioButton id="opt2" for="customRadio" itemIndex="1" />
<h:outputLabel for="opt2" value="Green" />
<p:radioButton id="opt3" for="customRadio" itemIndex="2" />
<h:outputLabel for="opt3" value="Blue" />
<p:commandButton value="select" ajax="true" onclick="selectRadios()" update="@form"/>
</h:panelGrid>
</p:outputPanel>
</h:form>
จาวาสคริปต์
<script type="text/javascript">
function selectRadios() {
jQuery("input[name='formID:customRadio']:first").prop('checked', true);
}
;
</script>
ขณะที่ฉันโหลดหน้าเว็บและคลิกที่ปุ่ม commandButton มันจะตรวจสอบปุ่มตัวเลือกแรกและใช้งานได้ดี แต่ฉันก็อยากจะทราบวิธีตรวจสอบอีกสองปุ่มด้วย
นอกจากนี้หากมีวิธีอื่นที่สามารถเปลี่ยนสถานะเป็น cheked ของ radiobutton นั้นได้โดยไม่ต้องใช้ javascript โปรดแจ้งให้เราทราบ
ขอบคุณสำหรับความช่วยเหลือ
-เควา
<[tagname]:[type ? ] [attributes]>
... มันไม่ใช่ HTML ธรรมดา พรีโปรเซสเซอร์ถูกใช้เพื่อตีความ ไม่รู้อันไหน...มีมากมาย ดังนั้นหากคุณสามารถโพสต์ HTML จริงได้ก็จะช่วยได้ - person Louys Patrice Bessette   schedule 25.10.2016<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:p="http://primefaces.org/ui">
- person Kevin Valdez   schedule 26.10.2016Doctype
ไม่เกี่ยวข้อง แต่ฉันแค่เพ่งความสนใจไปที่คำหลักPrimefaces
ซึ่งฉันไม่สนใจจนถึงตอนนี้ (แย่ของฉัน) ดูเหมือนว่าจะเป็น «ชุดคอมโพเนนต์ JSF ที่มีส่วนขยายต่างๆ» ข้อมูลอ้างอิง, p. 10/634. ฉันจะไม่อ่านมัน. หากต้องการให้ HTML ธรรมดาสำหรับคำถามของคุณ ซึ่งคุณสามารถแก้ไขได้ คุณจะต้องคัดลอก /วางแหล่งที่มาที่เกี่ยวข้องของหน้าที่คุณกำลังทดสอบ สามารถดูได้โดยเพิ่มview-source:
หน้า URL... ใน Chrome... (เบราว์เซอร์อื่นไม่ทราบ) - person Louys Patrice Bessette   schedule 26.10.2016