我需要你的帮助,
正如您在下面看到的,我最终将获得大量代码来完成 div 和输入字段的 onblur 和 on focus 场景。有没有办法创建一个“列表”并循环遍历它以逐行完成这段代码的工作?由于我将有超过 20 个字段,因此代码页会很长。
document.getElementById('f1').onfocus = function() {
document.getElementById('f1').style.border = '1px solid #0033CC'
document.getElementById('div_rssims_prefix').style.color = '#0033CC'
}
document.getElementById('f1').onblur = function() {
document.getElementById('f1').style.border = '1px solid #ABADB3'
document.getElementById('div_rssims_prefix').style.color = ''
}
document.getElementById('f2').onfocus = function() {
document.getElementById('f2').style.border = '1px solid #0033CC'
document.getElementById('div_rssims_firstname').style.color = '#0033CC'
}
document.getElementById('f2').onblur = function() {
document.getElementById('f2').style.border = '1px solid #ABADB3'
document.getElementById('div_rssims_firstname').style.color = ''
}
document.getElementById('f3').onfocus = function() {
document.getElementById('f3').style.border = '1px solid #0033CC'
document.getElementById('div_rssims_middlename').style.color = '#0033CC'
}
document.getElementById('f3').onblur = function() {
document.getElementById('f3').style.border = '1px solid #ABADB3'
document.getElementById('div_rssims_middlename').style.color = ''
}
一个理想的清单是:
f1,div_rssims_prefix
f2,div_rssims_firstname
f3,div_rssims_middlename
等等。