我用以下方式對點擊「Add按鈕」添加多格,如下面給出的小提琴:如何在bootstrap中添加動態div?
http://jsfiddle.net/harshmadhani/jpb93/
$(document).ready(function() {
var counter = 2;
$("#addButton").click(function() {
if (counter > 2) {
alert("Only 2 textboxes allowed");
return false;
}
$('<div/>',{'id':'TextBoxDiv' + counter}).html(
$('<label/>').html('Textbox #' + counter + ' : ')
)
.append($('<input type="text">').attr({'id':'textbox' + counter,'name':'textbox' + counter}))
.appendTo('#TextBoxesGroup')
counter++;
});
$("#removeButton").click(function() {
if (counter == 1) {
alert("No more textbox to remove");
return false;
}
counter--;
$("#TextBoxDiv" + counter).remove();
});
});
我必須用HTML添加文本,然後追加它。有沒有其他方法可以解決Bootstrap中的這個問題?
你說的意思'我有使用HTML來添加文本和追加它thereafter' ? – Starx
@Starx:這意味着我必須使用像html這樣的jQuery方法,並在點擊按鈕 –
後追加,你需要更深入的描述。 bootstrap是一個css基礎,並提供了像旋轉木馬,風格下拉等東西的小部件。你不能這樣做'append'工作_using_ bootstrap,ul必須使用jQuery。 – krishgopinath