jQuery可以生成select元素

jQuery可以生成select元素,jquery,select,option,Jquery,Select,Option,我有一个包含三个选择选项元素cat1、cat2、cat3的页面。预期的行为是当我在cat1中单击时,它应该生成cat2,当我单击cat2时,它应该生成cat3。我正在使用jquery-3.4.1。单击cat2时,我无法生成cat3 <html> <head> <script type='text/javascript' src='D:/test/jquery-form/jquery-3.4.1.js'></script> <script

我有一个包含三个选择选项元素cat1、cat2、cat3的页面。预期的行为是当我在cat1中单击时,它应该生成cat2,当我单击cat2时,它应该生成cat3。我正在使用jquery-3.4.1。单击cat2时,我无法生成cat3

<html>
<head>
<script type='text/javascript'
  src='D:/test/jquery-form/jquery-3.4.1.js'></script>
<script type="text/javascript">
  $(document).ready(function() {
    //change cat1
    $("#cat1").change(function(){
     console.log('cat1-change value');
     $('#cat2').remove();
     $('#frm').append("<select name='cat2' id='cat2'></select>");
     for(var i=1;i<5;i++)
     {
        str='<option value='+i+'>C2'+i+'</option>';
        $('#cat2').append(str);
     }
    });
    //change cat2
    $("#cat2").change(function(){
     $('#cat3').remove();
     $('#frm').append("<select name='cat3' id='cat3'></select>");
     for(var i=1;i<5;i++)
     {
        str='<option value=C3'+i+'>'+'C3'+i+'</option>';
        $('#cat3').append(str);
     }
    });
  });
</script>
</head>
<body>
 <form id="frm" name="frm" method="post">
  Cat1: 
  <select id="cat1">
    <option value="1">A</option>
    <option value="2">B</option>
    <option value="3">C</option>
  </select><br>
  <br />
  </form>
</body>
</html>

$(文档).ready(函数(){
//更换cat1
$(“#cat1”).更改(函数(){
console.log('cat1-change value');
$('#cat2')。删除();
$(“#frm”)。追加(“”);
对于(var i=1;i
$(文档).ready(函数(){
//更换cat1
$(“#cat1”).更改(函数(){
console.log('cat1-change value');
$('#cat2')。删除();
$(“#frm”)。追加(“”);
对于(var i=1;i