クリックで文字変更+文字スタイルも変更

[新着] Webテンプレートを仮オープンしました



0   名前: 匿名 : 2006/11/29(水) 22:07  ID:Igm6dEpu
クリックして文字を変更するタグで日記を設置しようと思っているのですが
クリック前とクリック後で文字のサイズやカラーを変更できるのでしょうか?
調べていてクリックで文字変更できるタグを見つけたので参考までに提示してみます
<SCRIPT language="JavaScript">
<!--
var x=0;var t = new Array("文字A","文字B","文字C","文字D");
function ok(){if((x+1) <= t.length){document.a.b.value=t[x];}x=x+1;}
//-->
</SCRIPT>
<BODY onLoad="ok()">
<FORM NAME="a">
<INPUT TYPE="BUTTON" ONCLICK="ok()" value="実行" style="color:#008000;background:#FFA0A0;width:50"> 
<INPUT TYPE="TEXT" NAME="b" value="文字@" style="color:#00FF00;background-color:#404040">

このタグでいうと
文字@をsize=2にとして文字Aをsize=7のようにしたいのです
タグではそのようなことはできないのでしょうか?
わかる方いましたら返答お願いしますm(__)m

1   名前: NullPo : 2006/11/29(水) 22:07  ID:Z0FHbpib
<script type="text/javascript">
<!--

window.onload = function()
{
  ok();
}

function ok()
{
  var t = new Array("文字 2", "文字 3", "文字 4", "文字 5");

  if(typeof this.x == "undefined")
    this.x = 0;

  if( (this.x + 1) < t.length) {
    var textB = document.getElementById("b")
    textB.value = t[this.x];
    textB.style.fontSize = (this.x + 7) + "px";
  }

  this.x++;
}

// -->
</script>

<form id="a">
<input type="button" onclick="ok();" value="実行" style="color:#008000; background:#ffa0a0; width:50px;">
<input type="text" id="b" name="b" value="文字 1" style="font-size:2px; color:#00ff00; background-color:#404040;">
</form>


2   名前: akippo : 2006/11/29(水) 22:07  ID:RX23FLgn
>>1 NullPoさんの回答
これだと、配列の中身が全部出ないのじゃないですか。
試してません。外してたらすいません。

3   名前: NullPo : 2006/11/29(水) 22:07  ID:Z0FHbpib
>>2
む、=を見落としてた。
訂正ありがとう。

4   名前: 匿名 : 2006/11/29(水) 22:07  ID:Igm6dEpu
回答ありがとうございますm(__)m

"文字@"などの""の中に font size= などはやはりむりですよね?

5   名前: NullPo : 2006/11/29(水) 22:07  ID:1Bb3RL38
>>4
テキストを展開して適切に処理すればそれも可能です。
でもこういった感じにしたほうが楽ですかね。
<script type="text/javascript">
<!--

window.onload = function()
{
  ok();
}

function ok()
{
  var t = new Array(new Text("文字 2", 7), new Text("文字 3", 12), new Text("文字 4", 17), new Text("文字 5", 22));

  if(typeof this.x == "undefined")
    this.x = 0;

  if( (this.x + 1) <= t.length) {
    var textB = document.getElementById("b");
    textB.value = t[this.x].text;
    textB.style.fontSize = t[this.x].size;
  }

  this.x++;
}

function Text(text, size) {
  this.text = text;
  this.size = size + "px";
}

// -->
</script>

<form id="a">
<input type="button" onclick="ok();" value="実行" style="color:#008000; background:#ffa0a0; width:50px;">
<input type="text" id="b" name="b" value="文字 1" style="font-size:2px; color:#00ff00; background-color:#404040;">
</form>


6   名前: 匿名 : 2006/11/29(水) 22:07  ID:Igm6dEpu
ありがとうございます(゚∀゚)
これなら日記を書くのでも楽そうです
ホントに感謝しますm(__)m
またわからないことがあったらお尋ねさせてもらいます

一覧へ戻る