下图显示了我的网页部分。我正在使用php开发我的网站。
如果我在draft
列表菜单中选择一个选项,则选择以下字段中的选项,例如,选择1,选择2将更改。我使用onchange
做到了这一点。我从onchange获取id并在select查询中使用该id从数据库中获取详细信息,并且获取的数据将在下面的listmenus中替换。
我需要通过仅刷新该部分而不是整个页面来完成它。有没有可能这样做?提前谢谢。
答案 0 :(得分:2)
根据问号标签,您已经在使用jQuery。那很好。
假设第一个选择名称是'draft',那么其他选择包含在id'picks'的元素中,并且/picks.php?id=X将为#picks生成一个合适的替换:
$('select[name=draft]').change(function() {
$.get('/picks.php', {'id': $(this).val()}, function(data) {
$('#picks').html(data);
})
})
答案 1 :(得分:0)
是的。这样做的技术称为ajax。我建议您查看一个javascript库,例如jQuery。它将使这个过程更容易。您需要的特定jQuery api引用是here。
例如你可以使用这样的东西:
// Wait till the page has loaded
$.ready(function() {
// create the on change event
$('#draftID').on('change', function() {
// get the new information from the server
$.ajax({
url: 'document.php?id=' + $('#draftID').val(),
success: function(data){
// this code is run when you get the reply;
$('#someDivID').html(data);
}
});
});
});