トップページ >  javascript >  テキストを作成する
初版2008/11/07: 最終更新日2008/11/07
  テキストを作成する
テキストを作成する
テキストを作成するには、document.createTextNode(テキスト) と記述します。
戻り値がテキストオブジェクトになります。単なるテキストではないので注意してください。
戻り値をalert()で表示すると、[Ojbect]と表示されます。
例えば、以下のボタンを押すと「ボタンです」と表示されます。ボタンは一度押すと、再度押せないようにしています。





サンプル
<html>
<head>
<title></title>
<script language="JavaScript">
<!--
function make(){
    text = document.createTextNode("ボタンです");
    document.getElementById("nobr").appendChild(text);
    document.getElementById("button").disabled = true;
}
// -->
</script>
</head>
<body>
<input type="button" value="テキスト作成" id="button" name="button" onclick="make()">
</body></html>