2017-05-30 31 views
1

我想通過下面的代碼追加4-5 apces,但它不是 工作。 Jquery的新手,JS請幫助。如何在jquery中追加4-5個空格?

$("#<%= 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("   "); 

注: - 我也到底(沒有工作)使用&nbspadding space但他們打印,因爲它是和空間不來

+1

嘗試用['&nbsp'](https://www.google.co.in/url?sa=t&rct=j&q=&esrc=s&source=web&cd=12&cad=rja&uact=8&sqi=2&ved=0ahUKEwiC9PfRoJfUAhXFqY8KHYYJAmEQFghUMAs&url=https% 3A%2F%2Fwww.w3schools.com%2Fhtml%2Fhtml_entities.asp與USG = AFQjCNEPHEcANIkULXIA3Lp4Lj-eCLuPvQ&SIG2 = _cvGI756RhdOlJTn9pYBPQ) – prasanth

+0

試過沒有工作@AlivetoDie –

+1

@prasad試過沒有工作 –

回答

1

使用&nbsp;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("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 

 
<div id="abc"></div>

注: - 如果您儘量選擇文本,然後你會看到,空格也被選中。

另一種方式來做到這一點: -

$("#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.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;see the space");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 

 
<div id="abc"></div>

注: - 確保jQuery庫腳本代碼前加入,否則將無法正常工作,您將獲得您的瀏覽器控制檯中出現錯誤$ is undefined

1

這就是HTML工作原理:white-space is collapsed合併成一個空間。如果您需要硬編碼的重複空格,則需要插入一個文字U+00A0 NO-BREAK SPACE字符。有很多種方法可以做到這一點:

  • 類型它就好了(你也可以使用剪貼板)
  • 插入一個JavaScript實體
  • 插入一個HTML實體

片段說明#2,#3(編輯器將轉換角色,以定期空間):

$("div:nth-of-type(1)").text("One\u00A0\u00A0\u00A0\u00A0Two"); 
 
$("div:nth-of-type(2)").html("One&nbsp;&nbsp;&nbsp;&nbsp;Two");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
 
<div></div> 
 
<div></div>