2017-04-03 17 views
0

javascriptのボタンでブートストラップツールチップを作成しようとしています。javacriptのボタンに 'data-toggle'属性を追加します。

button = document.createElement("Input"); 
    button.src = "/images/icon_trash_red.png"; 
    button.width = '20'; 
    button.type = 'image'; 
    button.onclick = function() { 
     RemoveItem(this); 
    }; 
    button.style.marginLeft = '70px'; 
    button.title = "Remover aluno"; 
    button.setAttribute("data-toggle", "tooltip"); 

「setAttributeメソッドは、」私が変更された場合ので、正常に動作しているようだ:これは私がこれまで持っているものである

<input type="image" src="~/images/icon_trash_red.png" class="m-l-20" onclick="RemoveItem(this)" height="20" data-toggle="tooltip" data-placement="right" title="Remover aluno" /> 

この

は私が達成しようとしているものですこのようなものに: button.setAttribute("height", "50px");それが動作します。

私が間違っていることは何ですか?

答えて

3

属性を要素に追加しますが、ツールチップを初期化する必要があります。

// initialize tooltip for all elements which has the data-toggle attribute 
$('[data-toggle="tooltip"]').tooltip() 

// or initialize just for the button 
$(button).tooltip() 

注:コードは、要素に属性を追加した後でなければなりません。

+0

私はすでにそれをやっています。 – perozzo

+0

@Perozzoだから、あなたの質問は、属性が追加されるときは何ですか? – Alex

+0

@Perozzo:フィドルでコードを共有できますか? –

関連する問題