0

谁能告诉我剧院我如何将值设置为 DIV TAG DYNAMICALLY USING javascript

<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>
4

2 回答 2

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;
于 2012-08-07T13:04:38.100 回答
0

获取当前年份

select = document.getElementById("CYear");
year = select.options[select.selectedIndex].innerHTML;

将其设置在您的 div 中

document.getElementById("div.sd").innerHTML=year;
于 2012-08-07T13:13:53.367 回答