我正在使用Bootstrap来设置我的网页样式,它几乎完美,
但是当我尝试使用$.append()向页面添加新的html时.那么新的html没有获得默认的bootstrap样式.
这是我的相关html:
但是当我尝试使用$.append()向页面添加新的html时.那么新的html没有获得默认的bootstrap样式.
这是我的相关html:
<div id="lines"> <div id="line1"> <input type="tel" class="Numbers" id="Number1" /> <input type="tel" class="Numbers" id="Number2" /> <input type="tel" class="Numbers" id="Number3" /> <input type="tel" class="Numbers" id="Number4" /> <input type="tel" class="Numbers" id="Number5" /> <input type="tel" class="Numbers" id="Number6" /> <input type="tel" class="Numbers" id="StrongNumber1" style="background-color:cyan"/> <button class="btn btn-primary addbtns" id="btnAdd1" onclick="addLine()">+</button> <button class="btn btn-primary addbtns" id="btnMinus1" disabled="disabled">-</button> </div> </div>
这是我的JQuery:
function addLine() { $('#btnAdd' + lineCounter).attr('disabled','true'); $('#btnMinus' + lineCounter).attr('disabled','true'); ++lineCounter; var line = "<div id='line" + lineCounter + "'>" + "<input type='tel' class='Numbers' id='Number" + lineCounter + "' />" + "<input type='tel' class='Numbers' id='Number" + lineCounter + "' />" + "<input type='tel' class='Numbers' id='Number" + lineCounter + "' />" + "<input type='tel' class='Numbers' id='Number" + lineCounter + "' />" + "<input type='tel' class='Numbers' id='Number" + lineCounter + "' />" + "<input type='tel' class='Numbers' id='Number" + lineCounter + "' />" + "<input type='tel' class='Numbers StrongNumber' id='StrongNumber" + lineCounter + "' style='background-color:cyan' />" + "<button class='btn btn-primary addbtns' id='btnAdd" + lineCounter + "' onclick='addLine()'>+</button>" + "<button class='btn btn-primary addbtns' id='btnMinus" + lineCounter + "' onclick='removeLine()'>-</button>" + "</div>"; $('#lines').append(line).fadeIn('slow'); }
编辑:
好吧,我试图用最简单的页面和简单的追加重现错误.还把JS’转换为’像@Sherbrow建议的那样,它仍然无法正常工作..
这是我的HTML:
<html xmlns="http://www.w3.org/1999/xhtml"> <link href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css" rel="stylesheet"> <link href="test.css" rel="stylesheet"/> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <script src="test.js"></script> <head></head> <body dir="rtl"> <div id="lines"> <div id="line1"> <input type="tel" class="Numbers" id="Number1" /> <input type="tel" class="Numbers" id="Number2" /> <input type="tel" class="Numbers" id="Number3" /> <input type="tel" class="Numbers" id="Number4" /> <input type="tel" class="Numbers" id="Number5" /> <input type="tel" class="Numbers" id="Number6" /> <input type="tel" class="Numbers" id="StrongNumber1" style="background-color:cyan"/> <button class="btn btn-primary addbtns" id="btnAdd1" onclick="addLine()">+</button> <button class="btn btn-primary addbtns" id="btnMinus1" disabled="disabled">-</button> </div> </div> </body> </html>
我的CSS:
body { background-color:#E46C0B; text-align:center; } .Numbers { width: 16px; }
我的JavaScript:
var lineCounter=1; function addLine() { $('#btnAdd' + lineCounter).attr('disabled','true'); ++lineCounter; var line = '<div id="line' + lineCounter + '">' + '<input type="tel" class="Numbers" id="Number' + lineCounter + '1" />' + '<input type="tel" class="Numbers" id="Number' + lineCounter + '2" />' + '<input type="tel" class="Numbers" id="Number' + lineCounter + '3" />' + '<input type="tel" class="Numbers" id="Number' + lineCounter + '4" />' + '<input type="tel" class="Numbers" id="Number' + lineCounter + '5" />' + '<input type="tel" class="Numbers" id="Number' + lineCounter + '6" />' + '<input type="tel" class="Numbers StrongNumber" id="StrongNumber"' + lineCounter + '" style="background-color:cyan" />' + '<button class="btn btn-primary addbtns" id="btnAdd"' + lineCounter + '" onclick="addLine()">+</button>' + '<button class="btn btn-primary addbtns" id="btnMinus"' + lineCounter + '" onclick="removeLine()">-</button>' + '</div>'; $('#lines').append(line); }
我究竟做错了什么?
谢谢你的答案:)