日期:2014-05-16 浏览次数:20377 次
$("select.cmdtype-list").change(function(){
var data = {id: $('select.cmdtype-list option:selected').val()};
alert(getRootPath() + '/task/getcommand');
$.getJSON(getRootPath() + '/task/getcommand', data, function(json){
var vx = json.text;
$(".cmd_prj").empty();
$.each(vx,function(i,item){
$(".cmd_prj").append(item);
});
});
})
//你的代码改成
var vx = json.text;
$(".cmd_prj option").remove();
var str='';
$.each(vx,function(i,item){
str=str+"<option>"+item+"</option>";
});
$("select").append(str);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function(){//我的测试用例
var a=[1,2,3];
$("#abv").click(function(){
$("select option").remove();
var str='';
$.each(a,function(i,j){
str=str+"<option>"+j+"</option>";
});
$("select").append(str);
});
})
</script>
<input type="button" id="abv" value="测试用按钮"/>
<select>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>