昨天做了一个下拉菜单中的item从服务器加载,发现用在项目中并不合适,改用下拉选择框
前台代码:
<span style="font-family:Times New Roman;font-size:18px;"> <div class="form-group">
<label class="col-md-2 control-label" for="unitpart">设备分中心</label>
<div class="col-md-10">
<select class="form-control" id="unitItem"></select>
</div>
</div></span>
<span style="font-family:Times New Roman;font-size:18px;"><span style="white-space:pre"> </span>var unitItem = $("#unitItem").val();//取出传到后台的option的value值</span>
<span style="font-family:Times New Roman;font-size:18px;"> $("#unitItem").bind("click", function () {
$.ajax({
url: "/control/showunit/",
dataType: "json",
success: function (data) {
$.each(data, function (index, units) {
$("#unitItem").append("<option value="+units.id+">" + units.unit + "</option>");
});
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("error");
}
});
});</span>
另外注意一点,在取radio单选框中的值和文本值时的代码:
<span style="font-family:Times New Roman;font-size:18px;"> <div class="form-group">
<label class="col-md-2 control-label">设备摄像头类型</label>
<div class="col-md-10" id="camera_type">
<label class="radio-inline">
<input type="radio" name="camera_type1" value="01" />xx1
</label>
<label class="radio-inline">
<input type="radio" name="camera_type1" value="02" />xx2
</label>
<label class="radio-inline">
<input type="radio" name="camera_type1" value="03" />xx3
</label>
<label class="radio-inline">
<input type="radio" name="camera_type1" value="04" />xx4
</label>
<label class="radio-inline">
<input type="radio" name="camera_type1" value="05" />xx5
</label>
<label class="radio-inline">
<input type="radio" name="camera_type1" value="06" />xx6
</label>
<label class="radio-inline">
<input type="radio" name="camera_type1" value="07" />xx7
</label>
<label class="radio-inline">
<input type="radio" name="camera_type1" value="08" />xx8
</label>
<label class="radio-inline">
<input type="radio" name="camera_type1" value="09" />xx9
</label>
<label class="radio-inline">
<input type="radio" name="camera_type1" value="10" />xx10
</label>
</div>
</div> </span>
<span style="font-family:Times New Roman;font-size:18px;">var devscameratypeid = $("#camera_type input[name='camera_type1']:checked").val();//这里取出的是radio的value值
var devscameratype = $("#camera_type input[name='camera_type1']:checked").parent().text();//这里取出的是type为radio的input标签的文本</span>