这纯粹是一个HTML问题。问题是您试图通过设置value=""
上的属性<select>
要素不是这样的<select>
作品
要将选项标记为默认选中,请<option>
标签需要提供selected
属性
例如,您正在输出以下内容:
<select id="j_applicationCategory" name="j_applicationCategory" value="UtilitiesApplication" style="width: 100%" />
<option value="GameApplication">GameApplication</option>
<option value="UtilitiesApplication">UtilitiesApplication</option>
<option value="DesignApplication">DesignApplication</option>
<option value="ReferenceApplication">ReferenceApplication</option>
</select>
您需要输出以下内容:
<select id="j_applicationCategory" name="j_applicationCategory" style="width: 100%">
<option value="GameApplication">GameApplication</option>
<option value="UtilitiesApplication" selected>UtilitiesApplication</option>
<option value="DesignApplication">DesignApplication</option>
<option value="ReferenceApplication">ReferenceApplication</option>
</select>
还要注意,我删除了一个不适当的结束语
/
从select标记。
WordPress具有实用功能,selected()
, 这使得基于当前值输出此属性更加容易:
echo \'<select id="j_applicationCategory" name="j_applicationCategory" style="width: 100%">\';
echo \'<option value="GameApplication" \' . selected( $j_applicationCategory, \'GameApplication\', false ) . \'>GameApplication</option>\';
echo \'<option value="UtilitiesApplication" \' . selected( $j_applicationCategory, \'UtilitiesApplication\', false ) . \'>UtilitiesApplication</option>\';
echo \'<option value="DesignApplication" \' . selected( $j_applicationCategory, \'DesignApplication\', false ) . \'>DesignApplication</option>\';
echo \'<option value="ReferenceApplication" \' . selected( $j_applicationCategory, \'ReferenceApplication\', false ) . \'>ReferenceApplication</option>\';
echo \'</select>\';