Php 在单击“提交”之前使用选定的选项值
显示了所选的选项,但我似乎无法用我的PHP代码找到解决方法。您必须使用AJAX调用:Php 在单击“提交”之前使用选定的选项值,php,javascript,Php,Javascript,显示了所选的选项,但我似乎无法用我的PHP代码找到解决方法。您必须使用AJAX调用: $(document).ready(function() { var type $('#abc').change(function() { var type = $('#abc').attr('value'); alert (type); } } 制作如下所示的PHP脚本: $(document).ready(function() { var type; $('#abc').c
$(document).ready(function() {
var type
$('#abc').change(function() {
var type = $('#abc').attr('value');
alert (type);
}
}
制作如下所示的PHP脚本:
$(document).ready(function() {
var type;
$('#abc').change(function() {
var type = $('#abc').attr('value');
$.post({
url: "/some/phpscript.php",
data: {t: type},
success: function(response) {
$('#div-content').html(response);
}
});
}
}
请显示整个html,您是否有
表单
标签?在发布到internet时,最好不要使用所有的大写字母,因为这被理解为代表叫喊(自Usenet问世以来,该指南已经实施了大约三十年)。制定问题时请小心。请说明上述必要性的目的好吗?因为您是从$\u POST
定义$ijk
(非常坏的名称顺便说一句),所以您无法通过标准get请求从中获取任何内容。提交表单意味着发出post请求,从而填充变量。如果没有发出post请求,难怪它会是空的。你希望它到底包含什么?是的,我使用了Ajax调用,它可以工作,但我的问题是,我所有的Html都是在事件发生后在我的页面上重复它自己。对于url参数,我将我的index.php放在我想要使用变量的页面上。但是,如果我使用另一个php文件作为url,一切正常,但我不能使用那里的变量。$('#abcd').change(function(){var name=$('#abcd').val();$.ajax({url:'students.php',data:'name='+name,success:function(data){$('#反馈').html(data)}}});现在,在students.php上,每当事件发生时,整个HTML都会自动重复
$(document).ready(function() {
var type;
$('#abc').change(function() {
var type = $('#abc').attr('value');
$.post({
url: "/some/phpscript.php",
data: {t: type},
success: function(response) {
$('#div-content').html(response);
}
});
}
}
<?php echo $_POST['t']; ?>
<div id="div-content"></div>