javascript - 如何在 jquery 中追加 4-5 个空格?

标签 javascript jquery

i am trying to append 4-5 apces by the below code but it's not working. new to Jquery,JS pls help.

$("#<%= 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 最后(没有用)但是它们按原样打印并且没有空格

最佳答案

使用 &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浏览器控制台错误。

关于javascript - 如何在 jquery 中追加 4-5 个空格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44257773/

相关文章:

javascript - OOP 方法中是否可以知道 ajax 调用何时完成

javascript - 是否有 xhr.overrideMimeType() 函数的跨浏览器替代方案?

javascript - jsonresult 错误结果

javascript - 选择不是链接的列表项

javascript - Angularjs 在具有验证的同一元素的指令中更改 ng-model

php - Node.js + Socket IO + Apache + PHP 从 url 中删除端口?

javascript - HTML 表单验证标签放置

javascript - 如何使用 React Native 在 if 条件内处理 Prop 导航

javascript - 表单提交不会间歇性地在谷歌浏览器中发生

javascript - Jquery 移动下拉菜单