getAttribute()とsetAttributeの使い方(1)

getAttribute()は要素の属性に値を参照する。setAttribute()はセットする。 使い方は、getAttribute("属性名")、setAttribute("属性名","値")。


実行結果


source


[ヘッダ部]
<script language="javascript">
function test()	{
	var output1 = f1.a1.getAttribute("value");
	var output2 = f1.a2.getAttribute("value");
	f1.a3.setAttribute("value",output1 + output2);
}
</script>

[本体]
<form id="f1">
<input id="a1" type="text" value="Windows">
<input id="a2" type="text" value="XP">
<input id="a3" type="text" value="">
<input id="a4" type="button" value="設定" onclick="test()">
</form>