ブートストラップ ボタンを動的に作成することは可能ですか? javascriptを使用して配列を作成するアイテムのリストを含むテキストファイルがあります。それが、各ボタン内のテキストであるアイテムを使用して動的にブートストラップ ボタンを作成したい場所です。テキストファイルに 10 個の項目がある場合、10 個のボタンが作成されます。誰かがそれを行う方法を教えてくれますか、それについてのチュートリアルを教えてくれますか?
EDIT(作成は可能ですが、ボタンが作成されたかどうかを確認するためのコードではありません):
createButtons():
$(function() {
$.ajax({
url : 'http://localhost:8080/SSAD/type.txt',
dataType : "text",
success : function (filecontent) {
var lines=filecontent.split('\n');
$.each(lines, function() {
if (this!='') {
var word = this;
word = word.toLowerCase().replace(/(?:_| |\b)(\w)/g, function(str, p1) { return p1.toUpperCase();});
if ($('button:contains("'+word+'")').length==0) {
var button='<button type="button" class="btn btn-block btn-inverse active" data-toggle="button tooltip" title="Click this to enable/disable viewing of'+this+'" onclick="toggleVisibility('+"'"+this+"'"+')">'+word+'</button>';
$(".crisisButtons").append(button);
}
}
});
}
});
});
HTML:
<button type="button" class="btn btn-block btn-inverse" onclick="createButtons">Click me!</button>
<div class="crisisButtons"></div>