我有一个select标签,哪个选项值来自数据库,通过PHP使用ajax。先前选择的值保存在DB中。
我想显示一个选择,显示先前选择的值(保存在数据库中)。
这是HTML代码
<select id='country'></select>
这是JS代码(ajax获取所有国家/地区列表)
$.ajax({
url: 'country.php',
scriptCharset: 'ANSI',
success:function(result) {
$('#country').append(result);
}
});
假设我想向国家显示哪个值为27,我该如何实现呢?
答案 0 :(得分:0)
$.ajax({
url:"country.php",
scriptCharset: 'ANSI' ,
success:function(result){
$('#country').append(result);
// Have you tried add this???
$('#country').val(27);
}
});
@thanks rahul
答案 1 :(得分:0)
使用选项进行另一个选择,并在js中,您可以使用onchange重新加载国家/地区列表。
答案 2 :(得分:0)
$。AJAX({
网址: “country.php”,
scriptCharset:'ANSI',
成功:函数(结果){
$
( '#国家')附加(结果);
$
( '#国家')VAL(VALUE);
}
});