【发布时间】:2019-11-04 06:29:08
【问题描述】:
我正在尝试删除两个带括号的单词之间的所有内容。词是:{start} 和 {end}
(function ($) {
$(document).ready(function(){
$('.well.save').on('mouseleave touchend', function(){
// alert('mouseleave touchend');
var $editor = $(".markItUpEditor");
var curValue = $editor.val();
//alert(curValue);
// check
var confCheck = curValue.includes("{start}");
//alert(confCheck);
if (confCheck == true) {
var myStr = $editor.val();
var subStr = myStr.match("{start}(.*){end}");
alert(subStr[1]);
//$editor.val(curValue);
}
});
})(jQuery);
上面的代码返回null。
我正在从文本区域获取内容。此文本区域有一个部分,其中包含在 mouseleave 上添加的文本。本节以单词{start} 开头并以单词{end} 结尾。现在我想删除这两个单词之间的所有内容以及这些单词,以便在下一次鼠标离开时我可以重新添加更新的信息。
Jquery 版本来自原生 Joomla 3。 textarea 包含以下内容:
There is some text in the message!
[confidential]
{start}
Site URL:
Site Username:
Site Password:
FTP URL:
FTP Username:
FTP Password:
Optional Information:
{end}
[/confidential]```
【问题讨论】:
-
1.请点击edit 2. 点击
[<>]sn-p 编辑器 3. 将RELEVANT JS(字符串示例和正则表达式)添加到JS 窗格。您的问题中没有 jQuery 相关性 -
@mplungjan
add RELEVANT JS (string examples and regex)这是什么意思?你想要一个文本区域的例子吗? -
我想要一个输入字符串、reexes 和预期输出的示例。我已经编辑了你的问题,因为一旦你有了字符串,就没有与 jQuery 相关的东西,所以请删除它和标签以获得正确的答案
-
@mplungjan 请不要删除大部分可能与您无关但可能与其他人相关的问题。至于字符串,我可以举个例子。但我不知道 rexexes。
-
但事实并非如此。如果您真的想要完整的 jQuery,您需要向我们提供 minimal reproducible example,其中包括您使用的 jQuery 版本和编辑器插件,以防它在将 {start} 和 {end} 传递给您的点击之前对其进行操作。跨度>
标签: javascript jquery