我试图通过以下代码附加4-5个apces,但事实并非如此 工作。 Jquery的新手,JS请帮助。
$("#<%= lbl100.ClientID %>").text("Your search request is too broad and the first 100 results are displayed.Please refine your search if your result does not show.").append(" ");
注意: - 我最后也使用了 
和adding space
(没有工作),但它们按原样打印,空间不到了
答案 0 :(得分:1)
将
与html()
一起使用,并确保ID: - <%= lbl100.ClientID %>
正确且存在。
实施例: -
$("#abc").html("Your search request is too broad and the first 100 results are displayed.Please refine your search if your result does not show. ").append(" ");
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="abc"></div>
&#13;
注意: - 如果您尝试选择文本,则会看到也选择了空格。
另一种方法: -
$("#abc").html("Your search request is too broad and the first 100 results are displayed.Please refine your search if your result does not show. see the space");
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="abc"></div>
&#13;
注意: - 确保在脚本代码之前添加了jQuery库,否则它将无效并且您的浏览器控制台中会出现$ is undefined
错误。
答案 1 :(得分:1)
HTML的工作原理:white-space is collapsed到一个空格中。如果您需要硬编码的重复空格,则需要插入文字U+00A0 NO-BREAK SPACE字符。有几种方法可以做到:
Snippet说明了#2和#3(编辑器会将角色转换为常规空间):
$("div:nth-of-type(1)").text("One\u00A0\u00A0\u00A0\u00A0Two");
$("div:nth-of-type(2)").html("One Two");
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div></div>
<div></div>
&#13;