将文本复制到剪贴板的最佳方法是什么?(多浏览器)
我试过了:
function copyToClipboard(text) {
if (window.clipboardData) { // Internet Explorer
window.clipboardData.setData("Text", text);
} else {
unsafeWindow.netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
const clipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper);
clipboardHelper.copyString(text);
}
}
Run Code Online (Sandbox Code Playgroud)
但在Internet Explorer中,它会出现语法错误.在Firefox中,它说unsafeWindow is not defined.
没有闪存的好技巧:Trello如何访问用户的剪贴板?
我JSON.stringify是一个json对象
result = JSON.stringify(message, my_json, 2)
Run Code Online (Sandbox Code Playgroud)
在2上面的说法应该是相当打印结果.如果我这样做,它会这样做alert(result).但是,我想通过将其附加到div中来将其输出给用户.当我这样做时,我只会出现一行.(我不认为它有效,因为中断和空格不被解释为html?)
{ "data": { "x": "1", "y": "1", "url": "http://url.com" }, "event": "start", "show": 1, "id": 50 }
Run Code Online (Sandbox Code Playgroud)
有没有办法以JSON.stringify漂亮的打印方式将结果输出到div?
我在使用<pre>标签时遇到问题<td>.我有JSF数据表和三列.我需要所有三列包含预格式化的文本.
如果我使用<pre>标签,文本会根据需要预先格式化,但列的宽度会比文本大得多.
我可以通过指定white-space: pre-line;in <pre>标签的样式在css中解决这个问题.但它只适用于Firefox和IE,Chrome忽略了这种风格.
所以我的问题是:有没有办法解决<td>其中包含<pre>标签的宽度?
编辑:
我的css课:
.dt_row {
height: 8px;
margin: 3px 3px 3px 3px;
color: #000000;
white-space: pre-line;
}
Run Code Online (Sandbox Code Playgroud)
我的数据表:
<h:dataTable value="#{searchBean.searchResult.concordances}"
var="concordance">
<h:column>
<pre class="dt_row">
#{concordance.left}
</pre>
</h:column>
<h:column>
<pre class="dt_row" style="color: blue;">
#{concordance.middle}
</pre>
</h:column>
<h:column>
<pre class="dt_row">
#{concordance.right}
</pre>
</h:column>
</h:dataTable>
Run Code Online (Sandbox Code Playgroud)
编辑:
我找到了解决方案.<pre>我使用过<code>而不是标记,现在所有数据都完美显示.
我遇到以下问题,我从包含换行符的API读取了数据字符串,\n并且希望在模板中正确显示它们。
但是当我做类似的事情时:
<p>{{ mytext }}</p>
Run Code Online (Sandbox Code Playgroud)
\n像普通文本一样,显示的文本中带有字符。
响应中的文本字符串格式为"Hello, \n what's up? \n My name is Joe"。
我在这里做错了什么?
我正在用户输入创建注释,并在用户单击"提交"后使用Mustache.js呈现它们.我意识到我可以替换用户输入换行符(\n)<br/>以呈现为HTML中断,例如
myString.replace(/\n/g, '<br />');
我意识到我可以通过使用三个括号使Mustache不能逃脱HTML
{{{myString}}}
但是,我想要逃避所有用户HTML,因为Mustache通常会使用双括号{{ ... }},但允许换行符除外<br/>
做这个的最好方式是什么?我可以在渲染后替换换行符,但这似乎是一个非常低效的解决方案,而且我认为必须有更好的方法.
我不明白为什么有两个属性似乎做同样的事情,但它们的相互关系似乎没有在规范中定义.
http://dev.w3.org/csswg/css-text-3/#word-break-property
http://dev.w3.org/csswg/css-text-3/#overflow-wrap-property
例如,如果我想按文件包装文本如何在预标记中包装文本?,有些行包含没有空格的字符串(这似乎使Chrome认为它们是不可破坏的(即使它们确实有逗号等)),我是否要使用word-break: break-all或者word-wrap: break-word除此之外white-space: pre-wrap?
我正在尝试禁用 HTML pre 标签中的水平滚动
我试过这个:
pre {
height: auto;
max-height: 500px;
overflow:hidden;
background-color: #eeeeee;
}Run Code Online (Sandbox Code Playgroud)
但它不能正常工作
它看起来像这样:
文本继续向左边缘。(我的html页面的方向是RTL Right to Left)
有什么建议吗?
模型:
Field('text1', type='text', length=1000, notnull=True)
Run Code Online (Sandbox Code Playgroud)
功能:
def textinput():
f=SQLFORM(db.example, fields=['text1'])
if f.accepts(request.vars, session):
return dict(form=f)
Run Code Online (Sandbox Code Playgroud)
我希望能够以正确的行间距/格式显示'text1'字段.如果用户要按表单中的[enter]键开始新行或整个新段落,我希望这反映在视图上.
例如,如果用户将以下内容输入SQLFORM:
This is a paragraph. Blah blah blah blah blah blah blah.
Blah blah blah blah blah blah blah blah blah.
Blah blah blah blah.
This is another paragraph. Blah blah blah blah blah.
Blah blah blah blah blah.
Run Code Online (Sandbox Code Playgroud)
我希望它与视图中的完全一样,而不是让它全部没有间距.我该怎么做呢?我正在考虑使用.replace方法并用换行符替换所有[enter]击键,但我不知道该怎么做.我在谷歌搜索过但我无法找到确切的问题.
任何帮助将不胜感激.谢谢.
我有以下代码,我正在尝试测试如何在我的网站上使用预格式。包含 pre 后,字体会发生变化,并且线条不会中断以适合 200px 划分。我想保持默认的字体大小、样式和系列。注意:我不想使用溢出方法。我想要这样的输出
"Sometimes it is very hard to code but by
circumstance you find yourself struggling
to fit in the game .
Awesome feelings come and disappear.
Niggas say this game is for the patient hearts.
You nigga is this true??
Nigga love style
keep in touch with us at any given time"
Run Code Online (Sandbox Code Playgroud)
加上默认的文本字体
<html>
<head>
<title>Test</title>
<style>
{
pre{
font-family: monospace;
text-wrap: unrestricted;
}
}
</style>
</head>
<body>
<div style='width:200px;'>
<pre>Sometimes it is very hard to …Run Code Online (Sandbox Code Playgroud) javascript ×5
css ×4
html ×4
pre ×2
clipboard ×1
copy-paste ×1
css3 ×1
jquery ×1
json ×1
line ×1
mustache ×1
newline ×1
pretty-print ×1
spacing ×1
string ×1
stringify ×1
vuejs2 ×1
web-frontend ×1
web2py ×1
word-break ×1
word-wrap ×1