Javascript 如何将值从HTML下拉框发送到JQuery函数
我对JQuery非常陌生,对javascript没有太多经验,经过几个小时的努力,我放弃了。我知道如何在PHP中实现这一点,但在JQuery中尝试时,我缺少了一些东西 我有一个html文件,它生成一个dorpdown框,看起来像tihs:Javascript 如何将值从HTML下拉框发送到JQuery函数,javascript,jquery,Javascript,Jquery,我对JQuery非常陌生,对javascript没有太多经验,经过几个小时的努力,我放弃了。我知道如何在PHP中实现这一点,但在JQuery中尝试时,我缺少了一些东西 我有一个html文件,它生成一个dorpdown框,看起来像tihs: <form action="" method="GET"> <select id="countiesList" name="counties"> <option value="all" selected="select
<form action="" method="GET">
<select id="countiesList" name="counties">
<option value="all" selected="selected">All Counties</option>
<option value="county1">County 1</option>
<option value="county2">County 2</option>
...
</select>
</from>
各县
县1
县2
...
非常感谢 听起来您希望在更改后立即提交。在这种情况下,请使用如下方法:
$(function() { //run when the DOM is ready
$("#countriesList").change(function() { //this runs when the selection changes
$.post("myPage.php", { country: $(this).val() }, function(data) {
//use data here
});
});
});
这样做的目的是,当您的选择发生变化时,我们将发布到“myPage.php”
,它将获得一个post变量country
,该变量将是您选择的值(all
,country
,等等)。只需从$\u POST[“country”]
获取此信息,并在上面的回调中呈现您的响应…这将是数据。然后,您可以对该响应执行任何您想要的操作,例如,如果它是另一个带有state的
,您可以将其附加到某个位置,例如:
$("#nextDropDownContainer").html(data);
你到底想做什么?我不知道你说的“确认”按钮是什么意思,但你应该有某种“提交”按钮。另外-您确定要在此处使用method=“GET”
?