Jquery 过滤器<;选择>;与其他<;选择>;使用数据库mysql和php

Jquery 过滤器<;选择>;与其他<;选择>;使用数据库mysql和php,jquery,html,filter,option,Jquery,Html,Filter,Option,我有一个表单,用户必须选择第一个,它将在db上过滤第二个,然后显示给用户 我在一些网站上看到过,我想把它放在我的网站上 第一个 这个结果将进行第二次选择 <select name="prof" id="prof"> <option title="" value="">Select ...</option> <option value="1">1.1</option> <option value="2">

我有一个表单,用户必须选择第一个
,它将在db上过滤第二个
,然后显示给用户

我在一些网站上看到过,我想把它放在我的网站上

第一个

这个结果将进行第二次选择

<select name="prof" id="prof">
    <option title="" value="">Select ...</option>
    <option value="1">1.1</option>
    <option value="2">1.2</option>
    <option value="3">1.3</option>
</select>

选择。。。
1.1
1.2
1.3
当查询运行时,它将显示在“搜索…”

如果我想错了,请帮助我,并给我一些想法


谢谢

正如@dontHaveName所建议的,使用一个类似以下内容的Ajax调用:

$('#area').on('change', function(e) {

  $.ajax({
    url: '/jobs/options/',
    type: 'POST',
    data: $(e.target).val(),
    dataType: 'html',
    success: function(opts) {
      $('#prof').html(opts);
    },
    error: function(xhr, status, err) {
     console.log(err); 
    }
  });

});
<html>
<body>

<script language=JavaScript>

//new hash is created
var area_prof = new Object();

// hash is being populated
area_prof["f"] = new Array("1.1","1.2","orange");
area_prof["s"] = new Array("2.1","2.2","white");
area_prof["t"] = new Array("3.1","3.2","3.3","hello world");

function populate()
{
var value=document.getElementById("area").options[document.getElementById("area").selectedIndex].value;

while (document.getElementById("prof").options[1])
    {
    document.getElementById("prof").options[1] = null;
    }

for (var i=0; i<area_prof[value].length; i++)
    {
    document.getElementById("prof").options[i+1] = new Option(area_prof[value][i],i);
    }
}

</script>

<select name="area" id="area" onChange=populate()>
    <option title="" value="">Select ...</option>
    <option value="f">First</option>
    <option value="s">Second</option>
    <option value="t">third</option>
</select>

<select name="prof" id="prof">
    <option title="" value="">Select ...</option>
</select>

</body>
</html>

一些Ajax代码来自内存,因此如果您遇到错误,请告诉我。

如果您选择的对象上没有多少项,我建议您将所有可能的内容加载到JavaScript哈希中。在本例中,使用PHP程序创建并填充此哈希。一旦用户更改了第一个select元素,您就可以调用一个函数来填充第二个select元素,如下所示:

$('#area').on('change', function(e) {

  $.ajax({
    url: '/jobs/options/',
    type: 'POST',
    data: $(e.target).val(),
    dataType: 'html',
    success: function(opts) {
      $('#prof').html(opts);
    },
    error: function(xhr, status, err) {
     console.log(err); 
    }
  });

});
<html>
<body>

<script language=JavaScript>

//new hash is created
var area_prof = new Object();

// hash is being populated
area_prof["f"] = new Array("1.1","1.2","orange");
area_prof["s"] = new Array("2.1","2.2","white");
area_prof["t"] = new Array("3.1","3.2","3.3","hello world");

function populate()
{
var value=document.getElementById("area").options[document.getElementById("area").selectedIndex].value;

while (document.getElementById("prof").options[1])
    {
    document.getElementById("prof").options[1] = null;
    }

for (var i=0; i<area_prof[value].length; i++)
    {
    document.getElementById("prof").options[i+1] = new Option(area_prof[value][i],i);
    }
}

</script>

<select name="area" id="area" onChange=populate()>
    <option title="" value="">Select ...</option>
    <option value="f">First</option>
    <option value="s">Second</option>
    <option value="t">third</option>
</select>

<select name="prof" id="prof">
    <option title="" value="">Select ...</option>
</select>

</body>
</html>

//创建新的哈希
var area_prof=新对象();
//正在填充哈希
面积_prof[“f”]=新阵列(“1.1”、“1.2”、“橙色”);
area_prof[“s”]=新阵列(“2.1”、“2.2”、“白色”);
area_prof[“t”]=新阵列(“3.1”、“3.2”、“3.3”、“你好世界”);
函数填充()
{
var value=document.getElementById(“区域”).options[document.getElementById(“区域”).selectedIndex].value;
while(document.getElementById(“prof”).options[1])
{
document.getElementById(“prof”).options[1]=null;
}
对于(var i=0;i

致以最良好的祝愿


Eduardo Maia

现在还不清楚你的问题是什么,使用jquery ajax功能这是一个求职网站,所以我需要对该区域进行筛选,然后在展示完角色后,我无法加载所有内容,因为它太重了。但非常感谢!!