我試圖使用jQuery追加空格。這些示例都不工作:使用jQuery追加空格
$("#mySelector").append($(" ")); $("#mySelector").append($(" "));
任何想法?
我試圖使用jQuery追加空格。這些示例都不工作:使用jQuery追加空格
$("#mySelector").append($(" ")); $("#mySelector").append($(" "));
任何想法?
如何
$("#mySelector").append(" "); // or with & nbsp;
未經測試(可能有點矯枉過正):
$("").append($("<p> </p>").text());
;創建一個jQuery插件功能重用它時,你需要把空間。這樣你將始終保持一致。
if(!$.space) {
$.space = function(noOfSpaces) {
var space = " ", returnValue = "";
for(var index=0; index < noOfSpaces; index++) {
returnValue += space;
}
return returnValue;
}
}
alert("Stack" + $.space(6) + "Overflow");
這與OP的問題無關,他沒有問如何創建一個空間填充字符串。 – 2017-03-03 16:55:37
在我來說,我做了以下內容:
$('.colwid10a').each(function() {
if ($(this).is(':empty')) {
$(this).append(" ");
}
});
$('.colwid12').each(function() {
if ($(this).find('a').is(':empty')) {
$(this).find('a').append(" ");
}
});
這是jQuery的正確的答案,或者你可以只使用CSS:#mySelector {填充右:1EM; } – Mottie 2009-10-01 03:36:50
謝謝你,Ólafur。我太努力了:) – 2009-10-01 15:09:05