我在文本框中的值为'203',因为'0'应该每次递增[1,2,3,4,5,6,7,8,9,A,B,C,D ,E,F,G,H,I,....... Z]所以下一个增量值应为'213,223,233,243,253,263,273,283,293,2A3,2B3,2C3,2D3,2E3 ....'
所以我创建了一个下拉框'revision',其值为[1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H ,我,....... Z]
使用sustr我剥离'0'位置,我得到变量'value1'的值。
var value1=item.substr(0,1)
var arr = document.getElementsByName('revision')
var x = arr[0].selectedIndex
如何比较value1
中的arr[0].length
和下拉数据中的下一个增量?
答案 0 :(得分:0)
尝试
var currentIndex = 0;
function createOption(){
var select = document.getElementById("revision");
for(var i = 1; i <= 9 ; i++){
var opt = document.createElement("option");
opt.value = i;
opt.innerHTML = i;
select.appendChild(opt);
}
for(var i = 65; i <= 90; i++){
var opt = document.createElement("option");
opt.value = String.fromCharCode(i);
opt.innerHTML = String.fromCharCode(i);
select.appendChild(opt);
}
}
createOption();
document.getElementById("btn").onclick = function(){
currentIndex ++;
var txt = document.getElementById("txt");
var select = document.getElementById("revision");
var lastChar = txt.value.substr(txt.value.length - 1, 1);
var firstChar = txt.value.substr(0, 1);
select.value = select.childNodes[currentIndex].value;
txt.value = firstChar + select.childNodes[currentIndex].value + lastChar;
};
这是DEMO