在visualforce中选中复选框后显示文本字段

use*_*080 7 salesforce visualforce

我有一个要求,当选中复选框时,必须使文本字段可编辑或呈现,我该如何实现?

Ada*_*dam 11

这是一个严格的Visualforce代码示例,它也可以运行:

<apex:pageBlock id="theBlock">
   <apex:inputCheckbox value="{!theSObject.CheckBox__c}">
      <apex:actionSupport event="onchange" rerender="theBlock"/>
   </apex:inputCheckbox>

   <apex:inputText value="{!theSObject.TextField__c}" disabled="false" rendered="{!(theSObject.CheckBox__c == true)}"/>
   <apex:inputText value="{!theSObject.TextField__c}" disabled="true" rendered="{!(theSObject.CheckBox__c != true)}"/>

   <!-- Or to simply have a field that appears only when the box is checked -->
   <apex:inputText value="{!theSObject.TextField__c}" rendered="{!(theSObject.CheckBox__c == true)}"/>
</apex:pageBlock>
Run Code Online (Sandbox Code Playgroud)

除此之外,如果您希望在Apex中进行进一步处理,可以在动作支持中添加动作,如下所示:

<apex:actionSupport event="onchange" action="{!myMethod}" rerender="theBlock"/>
Run Code Online (Sandbox Code Playgroud)

希望有所帮助