HTML 中的退格
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11329442/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Backspace in HTML
提问by Hashken
Is there a way to achieve Backspace functionality in HTML? Do we have any special tags for this?
有没有办法在 HTML 中实现退格功能?我们有什么特殊的标签吗?
An example showing the need for such a thing can be found in StackOverflow itself. Please refer to Get current stack trace in Java. In the top answer, @jinguiy is trying to express Thread.currentThread().getStackTrace() but because of the site's interpretation of links an unwanted space has been introduced.
可以在 StackOverflow 本身中找到显示需要这种东西的示例。请参阅在 Java 中获取当前堆栈跟踪。在最佳答案中,@jinguiy 试图表达 Thread.currentThread().getStackTrace() 但由于站点对链接的解释,引入了不需要的空间。
If there is a way to include a backspace this can be avoided.
如果有一种方法可以包含退格键,则可以避免这种情况。
This is just one example, but in many contexts where we can't control certain part of the output, having a backspace functionality in HTML can be quite useful.
这只是一个例子,但在我们无法控制输出的某些部分的许多情况下,在 HTML 中具有退格功能可能非常有用。
采纳答案by Billy Moon
HTML is stateless, so there is no possibility of backspace functionality with HTML alone. You could do something with javascript to achieve a similar effect.
HTML 是无状态的,因此单独使用 HTML 不可能有退格功能。你可以用 javascript 做一些事情来达到类似的效果。
Another approach, would be to buffer your output before sending it, and then process the buffered output. You could roll your own backspace tag, and then when processing the buffer, delete the backspace tag, and the character/tag before it.
另一种方法是在发送之前缓冲您的输出,然后处理缓冲的输出。您可以滚动自己的退格标记,然后在处理缓冲区时,删除退格标记及其前面的字符/标记。
回答by Guffa
You can use a negative margin:
您可以使用负边距:
HTML:
HTML:
<span>this is</span> <span class="backspace">a test</span>
CSS:
CSS:
.backspace { margin-left: -4px; }
回答by Nicolo
Gulta's answer is best. Here is how to do this all within your html source:
古尔塔的答案是最好的。以下是如何在您的 html 源代码中执行此操作:
<!-- horizontal backspace; adjust the amount of space by changing 4px -->
<style type="text/css">span.backspace{margin-left: -4px}</style>
<!-- The above sets up a "backspace command" in html in the style css-->
this is<span class="backspace"></span>a test
<!-- which can be placed any where after, and will output
this isa test
-->
回答by hockeyman
As I know HTML has no tags to do it. You need to add some other language to your code to do such things.
据我所知,HTML 没有标签可以做到这一点。您需要在代码中添加一些其他语言才能执行此类操作。
回答by Elisa
I don't think there's such a functionality in HTML... but, depending on the effect you're trying to achieve (is it a matter of visualization only?), you could act on word-spacingor letter-spacing
我认为 HTML 中没有这样的功能……但是,根据您想要达到的效果(是否只是可视化问题?),您可以对字间距或字母间距进行操作
You can also use other techniques, like setting a negative margin on the elements.
您还可以使用其他技术,例如在元素上设置负边距。
In the specific example you linked, the space is due to this rule in the CSS:
在您链接的特定示例中,空格是由于 CSS 中的此规则:
p code {
padding: 1px 5px;}
If you remove it with firebug, the space disappears, cause there isn't a space (try to copy and paste the text)
如果你用萤火虫删除它,空格就会消失,因为没有空格(尝试复制和粘贴文本)
Instead, if the matter is that there are unwanted spaces in the text, you can try with javascript (here an example) or processing the text with a server side language
相反,如果问题是文本中有不需要的空格,您可以尝试使用 javascript(这里是一个示例)或使用服务器端语言处理文本
回答by EngSaad
if you searching for simple and effective method to let user go back from your webpage you can use this JavaScript code
如果您正在寻找简单有效的方法让用户从您的网页返回,您可以使用此 JavaScript 代码
head section
头部部分
<script>
function goBack()
{
window.history.back()
}
</script>
and insert HTML in your body
并在您的正文中插入 HTML
<input type="button" value="Back" onclick="goBack()">