how can I give an array as options to select element?

后端 未结 5 1578
南笙
南笙 2020-12-08 15:43

I have a select element on my HTML page. I want to populate it with an array. as we can give an array as dataprovider to comboBox in action script. I do the following

<
5条回答
  •  清歌不尽
    2020-12-08 16:09

    This is the best way you can get array values in combo box

    var states = new Array();
    states['India'] = new Array('Andhra Pradesh','Arunachal Pradesh','Assam','Bihar','Chhattisgarh','Goa','Gujarat','Haryana','Himachal Pradesh','Jammu and Kashmir','Jharkhand','Karnataka','Kerala','Madhya Pradesh','Maharashtra','Manipur','Meghalaya','Mizoram','Nagaland','Odisha','Punjab','Rajasthan','Sikkim','Tamil Nadu','Telangana','Tripura','Uttar Pradesh','Uttarakhand','WestBengal','Andaman and Nicobar Islands','Chandigarh','Dadra and Nagar Haveli','Daman and Diu','Lakshadweep','Puducherry'); 
    
    function setStates() {
    	var newOptions=states['India'];
    	var newValues=states['India'];
    	selectField = document.getElementById("state");
    	selectField.options.length = 0;
    	for (i=0; i
    State :
    

提交回复
热议问题