2010-12-06 12 views
0

JavaScriptを使用して、入力テキストフィールドのテキストの装飾を変更するにはチェックボックスを使用します。 これをチェックすると、入力テキストフィールドのテキストが太字になります。私はこのような何かを考えて)textdecoration入力フィールドを変更するチェックボックス

;

は、私はので、私はあなたたちとプロじゃない学んだ覚えておいてください。

var checkbox = create("input"); 
    checkbox.type = "checkbox"; 
    checkbox.id = "checkboxId" + counter; 
    div.appendChild(checkbox); 
    checkbox.onClick="boldChange(this)" 

var input = create("input"); 
    input.type = "input"; 
    input.id = "inputId" + counter; 
    div.appendChild(input); 



function boldChange() 
var boldgroup = document.getElementsByName(el.name); 
for (var b=0; boldgroup[b]; ++b) 
inputId.style.textDecoration = boldgroup[b].checked ? 'bold' : 'none'; 
} 

どうすればこの作品を作成できますか? はここで事前

+0

を ' text-decoration:bold'は無効ですCSS、IIRC –

答えて

2

にどうもありがとうございますあなたのコードに基づいて作業JSFiddle例である以上:Link to example

コードスニペット:(</body>以下の場所DOMのすべてがロードされるように)

<script> 
    var div = document.getElementById('div'), 
    counter = 0; 

    var checkbox = document.createElement("input"); 
    checkbox.type = "checkbox"; 
    checkbox.id = "checkboxId" + counter; 
    div.appendChild(checkbox); 
    checkbox.onclick = boldChange; 
    counter++; 

    var input = document.createElement("input"); 
    input.type = "text"; 
    input.id = "inputId" + counter; 
    div.appendChild(input); 



    function boldChange() { 
     input.style.fontWeight = (checkbox.checked)?'bold':'normal'; 
    } 
</script> 
+0

すごくありがとう!完璧に動作します – Opoe

+0

@Opoe:あなたは間違いなく正しい軌道に乗っていただけで、あなたのコードにいくつか微調整を加えなければなりませんでした:) – subhaze

+0

感謝します:)ありがとう – Opoe

関連する問題