【发布时间】:2021-06-22 10:00:55
【问题描述】:
我从此页面获得的以下代码按预期工作。
How can I replace newlines/line breaks with spaces in javascript?
var words = "car\r\n\r\nhouse\nhome\rcomputer\ngo\n\nwent";
document.body.innerHTML = "<pre>OLD:\n" + words + "</pre>";
var new_words = words.replace(/[\r\n\x0B\x0C\u0085\u2028\u2029]+/g," ");
document.body.innerHTML += "<pre>NEW:\n" + new_words + "</pre>";
但在我的例子中,words 变量只不过是表单中的文本,我正在寻找一种将这个脚本转换为书签的方法。小书签代码与常规代码有何不同?
【问题讨论】:
-
您能分享一个表单示例以及“表单中的文本”在上下文中的含义吗?
标签: bookmarklet