0
我想创建一个多选< select> with ajax和jquery。多选择html和jquery ajax
首先选择(c1)工作正常。当我点击它时会返回另一个选择(c2)。但是当我点击第二选择(c2)时,我可以得到第三选择(c3)。
HTML:
<table><tr><td id="cat1div">
<select name="c1">
<option value="">---</option>
<option value="1">Auto</select>
<option value="2">Moto</select>
</td>
<td id="cat2div"></td>
<td id="cat3div"></td>
</tr></table>
的jQuery:
$(document).ready(function() {
$("select[name=c1]").change(function() {
var id = $("select[name=c1] option:selected").val();
$.ajax({
url: "category.php?cat=2&id=" + id,
cache: false,
success: function (html) {
$('#cat2div').html(html);
}
});
});
$("select[name=c2]").change(function() {
alert('asad');
var id = $("select[name=c2] option:selected").val();
$.ajax({
url: "category.php?cat=3&id=" + id,
cache: false,
success: function (html) {
$('#cat3div select').html(html);
}
});
});
});
PHP:
<?if($_GET['cat']==2){?>
<select name="c2">
<option value="">---</option>
<?foreach($cat2[$_GET['id']] as $ca => $key){
?><option value="<?=$ca;?>"><?=$key;?><?}?>
</select>
<?}elseif($_GET['cat']==3){?>
<select name="c3">
<option value="">---</option>
<?foreach($cat3[$_GET['id']] as $ca => $key){
?><option value="<?=$ca;?>"><?=$key;?><?}?>
</select>
<?
对不起,我的英语水平,并感谢所有帮助
我不知道PHP,但它看起来好像他的(或她的)生成''...... – Pointy 2010-11-10 19:13:32