Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/474.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
Javascript 下拉列表选择不显示在div中_Javascript_Jquery_Html - Fatal编程技术网

Javascript 下拉列表选择不显示在div中

Javascript 下拉列表选择不显示在div中,javascript,jquery,html,Javascript,Jquery,Html,我希望displayround div显示在选择框中选择的内容。不知怎的,当我删除一些数组值时,它就停止工作了。。知道为什么吗 HTML: <div id="buttonholder"> <button id="previous">< Previous round</button> <button id="next">Next round ></button> <button id="current">>

我希望displayround div显示在选择框中选择的内容。不知怎的,当我删除一些数组值时,它就停止工作了。。知道为什么吗

HTML

<div id="buttonholder">
<button id="previous">< Previous round</button>
<button id="next">Next round ></button>
<button id="current">> Current round <</button>
<div style="font-size: 0;">
<form id="inputform">

<select name="rounds" id="selectbox">
    <option value="2013/2014">--- 2013/2014 ---</options>
    <option value="2012/2013">--- 2012/2013 ---</options>
    <option value="2011/2012">--- 2011/2012 ---</options>
    <option value="2010/2011">--- 2010/2011 ---</options>
    <option value="2009/2010">--- 2009/2010 ---</options>
    <option value="2008/2009">--- 2008/2009 ---</options>
    <option value="2007/2008">--- 2007/2008 ---</options>
    <option value="2006/2007">--- 2006/2007 ---</options>

</select>

</form>
</div>
<div id="displayround">

</div>
</div>
$(document).ready(function() { 

    var season = new Array();
    season[0]="2013/2014";
    season[1]="2012/2013";
    season[2]="2011/2012";
    season[3]="2010/2011";
    season[4]="2009/2010";
    season[5]="2008/2009";
    season[6]="2007/2008";
    season[7]="2006/2007";
    season[8]="2005/2006";

    $("#buttonholder").find("button").addClass("left")
    $("#buttonholder").find("#submit").removeClass("left").addClass("right")
    $("#buttonholder").find("#inputform").addClass("right");

    $("#displayround").text(season[0]).data('index', 0);

    $("#next").click(function () {
        var index = +$("#displayround").data('index') + 1;
        if (index >= season.length) index = 0;
        $("#displayround").text(season[index]).data('index', index);
    });

    $("#previous").click(function () {
        var index = +$("#displayround").data('index') - 1;
        if (index <= -1) index = season.length - 1;
        $("#displayround").text(season[index]).data('index', index);
    })

你再说一遍:),让我告诉你这个问题。现在选择的值类似于
2013/2014
,因此
“2013/2014”。匹配(/\d+/)
将返回
[“2013”]
一个数组。即使您转换了数据,也可以说是
2013
。你没有那么长的数组创建一个please:d这个看起来很奇怪:
var index=+$(“#displayround”).data('index')+1那个
+
在那里做什么?@corneéM,
+“1”
会把字符串转换成数字。我已经帮你做了
    $("#selectbox").change(function() {
        var index = $(this).val().match(/\d+/) - 1;
        $("#displayround").text(season[index]).data('index', index);
    });

}); //end of document.ready function