我正试图通过下面的代码附加4-5个附件,但它不起作用。JS是Jquery的新手,请提供帮助。
$("#<%= 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 (没有工作),但它们是按原样打印的,空间也不会出现。
发布于 2017-05-30 09:03:24
将 与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(" ");<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. 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错误。
发布于 2017-05-30 09:08:55
这就是HTML的工作方式:空隙坍塌了进入一个单独的空间。如果需要硬编码的重复空格,则需要插入一个文字U+00A0无间断空间字符。有几种方法可以做到:
代码片段说明了#2和#3 (编辑器将字符转换为常规空间):
$("div:nth-of-type(1)").text("One\u00A0\u00A0\u00A0\u00A0Two");
$("div:nth-of-type(2)").html("One Two");<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div></div>
<div></div>
https://stackoverflow.com/questions/44257773
复制相似问题