我希望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>
JQuery的:
$(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);
})
这个问题出现在我假设的这个函数中:
$("#selectbox").change(function() {
var index = $(this).val().match(/\d+/) - 1;
$("#displayround").text(season[index]).data('index', index);
});
}); //end of document.ready function