Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将值从返回到jQuery上的/下拉列表元素_Jquery_Html - Fatal编程技术网

将值从返回到jQuery上的/下拉列表元素

将值从返回到jQuery上的/下拉列表元素,jquery,html,Jquery,Html,这是HTML脚本 <div id="5"> <div class="niche">Click here to generate dropdownlist</div> <div> <div id="tests">This will change, but it won't when you change the dropdown list</div> jQuery var theNiche; $('.niche').cl

这是HTML脚本

<div id="5">
<div class="niche">Click here to generate dropdownlist</div>
<div>

<div id="tests">This will change, but it won't when you change the dropdown list</div>
jQuery

var theNiche;

$('.niche').click(function(){

    var theNiche = $(this).text();   
    var createSelect = $(document.createElement('select')).attr('id', 'sel-niche');
      createSelect.appendTo(this);
    $(this).replaceWith(createSelect);

var myOptions = {
      'Autos' : 'Autos',
      'Business' : 'Business',
      'Education' : 'Education',
      'Entertainment' : 'Entertainment',
      'Fashion' : 'Fashion',         
      'Food' : 'Food',
      'Health' : 'Health',
      'Home' : 'Home',
      'Insurance' : 'Insurance',
      'Gambling' : 'Gambling',
      'General' : 'General',
      'Music' : 'Music',
      'Real Estate' : 'Real Estate',
      'Sex' : 'Sex',
      'Shopping' : 'Shopping',
      'Sports' : 'Sports',
      'Technology' : 'Technology',
      'Travel' : 'Travel'
        };
        $.each(myOptions, function(val, thetext) {
            $('#sel-niche').append(
                $('<option></option>').attr('value',val).text(thetext)
            ); 
        });

        $('#sel-niche option[value="'+theNiche+'"]').attr('selected',true);
        $('#tests').html(theNiche);   
    });

var onChange = function(e){    
    $('#5 select').change(function(){
      alert($('#5 option:selected').text());
    }).change(onChange);
};

$('#5 select').change(onChange);
当我点击这里生成下拉列表时,div id=tests的文本将会改变。但当下拉列表显示时,我试图更改该值。div id=tests文本没有更改

我的错误在哪里


*这是我的第一篇帖子,很抱歉你用“5”作为ID。有效的ID不能以数字开头,也不能仅仅是一个数字


把它改成一个名字,说“五”,你的代码就可以用了。

我把它改成了五,但没有任何修正。id=测试仍然没有改变。期待着答案。。谢谢