ColdFusion select option 用法,看看哪种适合你的
程序员文章站
2022-05-06 22:37:59
...
1.
<cfscript>
Function setSelected(val1, val2){
if (val1 EQ val2)
{
Return 'selected="selected"';
}
else
{
Return '';
}
}
</cfscript>
<selectid="grade"name="grade">
<optionvalue="A" #setSelected('A', form.grade)#>A</option>
<optionvalue="B" #setSelected('B', form.grade)#>B</option>
<optionvalue="C" #setSelected('C', form.grade)#>C</option>
<optionvalue="D" #setSelected('D', form.grade)#>D</option>
<optionvalue="F" #setSelected('F', form.grade)#>F</option>
</select>
2.
<selectid="grade"name="grade">
<option value="A"<cfifform.grade='A'> selected="selected"</cfif>>A</option>
<option value="B"<cfifform.grade='B'> selected="selected"</cfif>>B</option>
<option value="C"<cfifform.grade='C'> selected="selected"</cfif>>C</option>
<option value="D"<cfifform.grade='D'> selected="selected"</cfif>>D</option>
<option value="F"<cfifform.grade='F'> selected="selected"</cfif>>F</option>
</select>
3.
<cfqueryname="getGrades"datasource="#application.dsn#">
select gradeLetter from Grades
</cfquery>
<cfselect
name="grade"
query="getGrades"
display="gradeLetter"
value="gradeLetter"
selected="#form.grade#"/>
4.
<cfparamname="form.grade"default="C">
<cfsetmydata=[{grade="A",value="A"},{grade="B",value="B"},{grade="C",value="C"},{grade="D",value="D"},{grade="F",value="F"}]>
<cfoutput>
<selectid="grade"name="grade">
<cflooparray="#mydata#"index="i">
<option value="#i['value']#"<cfifform.gradeEQi['grade']> selected="selected"</cfif>>#i['value']#</option>
</cfloop>
</select>
</cfoutput>
5.
<cfsavecontentvariable="GradeOptions">
A:A
B:B
C:C
D:D
F:F
</cfsavecontent>
<selectid="grade"name="grade">
<cfloopindex="CurOpt"list="#trim(GradeOptions)#"delimiters="#Chr(10)#">
<option value="#ListFirst(CurOpt,':')#"<cfifform.gradeEQListFirst(CurOpt,':')> selected="selected"</cfif>>#ListRest(CurOpt,':')#</option>
</cfloop>
</select>
6.
<cfsavecontentvariable="GradeOptions">
A
B
C
D
F
</cfsavecontent>
<selectid="grade"name="grade">
<cfloopindex="CurOpt"list="#trim(GradeOptions)#"delimiters="#Chr(10)#">
<option<cfifform.gradeEQCurOpt> selected="selected"</cfif>>#CurOpt#</option>
</cfloop>
</select>
7.
<cfparamname="form.grade"default="A">
<cfoutput>
<selectid="grade"name="grade">
<cfloopindex="code"from="65"to="90">
<option value="#Chr(code)#"<cfifform.gradeEQChr(code)> selected="selected"</cfif>>#Chr(code)#</option>
</cfloop>
</select>
</cfoutput>
8.
<cfsetGradeOptions=Grades.readAvailable()/>
<selectid="grade"name="grade">
<cfloopquery="GradeOptions">
<option value="#GradeCode#"
<cfifForm.GradeEQGradeCode>selected="selected</cfif>
>#GradeCode# - #GradeDesc#</option>
</cfloop>
</select>
9.
<selectid="grade"name="grade">
<option value="A"<cfifform.gradeEQ"A"> selected </cfif> >A</option>
<option value="B"<cfifform.gradeEQ"B"> selected </cfif> >B</option>
<option value="C"<cfifform.gradeEQ"C"> selected </cfif> >C</option>
<option value="D"<cfifform.gradeEQ"D"> selected </cfif> >D</option>
<option value="F"<cfifform.gradeEQ"F"> selected </cfif> >F</option>
</select>
10.
<scripttype="text/javascript">
jQuery(document).ready(function(){
$("#grade option[value='<CFOUTPUT>#FORM.Grade#</CFOUTPUT>']")
.attr('selected','selected');
});
</script>
<selectid="grade"name="grade">
<optionvalue="A">A</option>
<optionvalue="B">B</option>
<optionvalue="C">C</option>
<optionvalue="D">D</option>
<optionvalue="F">F</option>
</select>