我的js
<case value="select"> <div class="form-group item_{$[type]form.name} {$[type]form.extra_class}"> <label class="left control-label">{$[type]form.title}:</label> <div class="right"> <select name="{$[type]form.name}" id="province" onchange="changeCity($('#province option:selected') .val())" class="form-control select" {$[type]form.extra_attr}> <option value=''>请选择:</option> <foreach name="[type]form.options" item="option" key="option_key"> <php>if(is_array($option)):</php> <option value="{$option_key}" <eq name="[type]form.value" value="$option_key"> selected</eq> <foreach name="option" item="option2" key="option_key2"> {$option_key2}='{$option2}' </foreach>> {$option.title} </option> <php>else:</php> <option value="{$option_key}" <present name='[type]form.value'><eq name="[type]form.value" value="$option_key"> selected</eq></present>>{$option}</option> <php>endif;</php> </foreach> </select> </div> </div> </case>
<script> var array = new Array();//数组 //js中的二维数组的下标可以使字符串 <foreach name="[type]form.options" item="option" key="option_key"> <foreach name="option" item="option2" key="option_key2"> array['{option_key}']['{option_key2}'] = '{option2}'; </foreach> </foreach> function initProvince(value) { array[value].forEach(function(value,index,array){ var option = new Option(index, value); provinceObj.add(option); //把创建的option添加到下拉列表中 }); } </script> <case value="select"> <div class="form-group item_{$[type]form.name} {$[type]form.extra_class}"> <label class="left control-label">{$[type]form.title}:</label> <div class="right"> <select name="{$[type]form.name}" id="city" class="form-control select" {$[type]form.extra_attr}> <option value=''>请选择:</option> </select> </div> </div> </case>