With out changing the order of "select:Option" how to make a specific option as selected by default in visual force <apex:seleList>?

huangapple go评论74阅读模式
英文:

With out changing the order of "select:Option" how to make a specific option as selected by default in visual force <apex:seleList>?

问题

<apex:page>
    <apex:form>
        <apex:selectList size="1">
            <apex:selectOption itemLabel="猿" itemValue="猿"/>
            <apex:selectOption itemLabel="蝙蝠" itemValue="蝙蝠"/>
            <apex:selectOption itemLabel="猫" itemValue="猫"/>
            <apex:selectOption itemLabel="狗" itemValue="狗"/>
            <apex:selectOption itemLabel="大象" itemValue="大象"/>
        </apex:selectList>
    </apex:form>
</apex:page>

在不改变<apex:selectOption>的顺序的情况下,要使"狗"成为默认选择,您可以使用以下代码。

英文:
&lt;apex:page &gt;
    &lt;apex:form&gt;
        &lt;apex:selectList size=&quot;1&quot;&gt;
            &lt;apex:selectOption itemLabel=&quot;Ape&quot; itemValue=&quot;Ape&quot;/&gt;
            &lt;apex:selectOption itemLabel=&quot;Bat&quot; itemValue=&quot;Bat&quot;/&gt;
            &lt;apex:selectOption itemLabel=&quot;Cat&quot; itemValue=&quot;Cat&quot;/&gt;
            &lt;apex:selectOption itemLabel=&quot;Dog&quot; itemValue=&quot;Dog&quot;/&gt;
            &lt;apex:selectOption itemLabel=&quot;Elephant&quot; itemValue=&quot;Elephant&quot;/&gt;
    	&lt;/apex:selectList&gt;
    &lt;/apex:form&gt;
&lt;/apex:page&gt;

Here "Ape" is selected by default since it is the first option but With out changing the order of the <apex:selectOption> I want to make "Dog" as selected by default.

Please tell me how to achieve this without using Apex and without using script if possible
Thanks in advance

答案1

得分: 1

Without Apex and JavaScript? that's a lot of limitation and I don't know what's the point of the page, how are you going to use the value in any way.

You could always downgrade it all the way to pure HTML

&lt;apex:page&gt;
    &lt;select&gt;
        &lt;option&gt;Ape&lt;/option&gt;
        &lt;option&gt;Bat&lt;/option&gt;
        &lt;option&gt;Cat&lt;/option&gt;
        &lt;option selected=&quot;true&quot;&gt;Dog&lt;/option&gt;
        &lt;option&gt;Elephant&lt;/option&gt;
    &lt;/select&gt;
&lt;/apex:page&gt;
英文:

Without Apex and JavaScript? that's a lot of limitation and I don't know what's the point of the page, how are you going to use the value in any way.

You could always downgrade it all the way to pure HTML

&lt;apex:page&gt;
    &lt;select&gt;
        &lt;option&gt;Ape&lt;/option&gt;
        &lt;option&gt;Bat&lt;/option&gt;
        &lt;option&gt;Cat&lt;/option&gt;
        &lt;option selected=&quot;true&quot;&gt;Dog&lt;/option&gt;
        &lt;option&gt;Elephant&lt;/option&gt;
    &lt;/select&gt;
&lt;/apex:page&gt;

huangapple
  • 本文由 发表于 2023年5月18日 00:34:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76274318.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定