任何人都可以告诉我如何使用javascript动态设置DIV TAG的值
<div class="sD" style="width:55px;" id="CYearHold">
Here i have to display Current year
</div>
<select id="CYear" class="inputControl simple" style="width:55px;" name="currentYear" onChange="setYear1(this);">
</select>
答案 0 :(得分:2)
您可以使用innerHTML:
document.getElementById('CYearHold').innerHTML = 'something';
如果您想将所选年份放入div中,您可以这样做:
var e = document.getElementById("CYear");
var strYear = e.options[e.selectedIndex].value;
document.getElementById('CYearHold').innerHTML = strYear;
答案 1 :(得分:0)
获取当前年份
select = document.getElementById("CYear");
year = select.options[select.selectedIndex].innerHTML;
在div中设置
document.getElementById("div.sd").innerHTML=year;