【发布时间】:2012-06-26 00:46:48
【问题描述】:
如何删除空格、关键字及其后面的所有内容?这就是我要找的东西
var test = $('.replaceMe').attr('title').replace(/ /g, '');
<a class="replaceMe" href="#" title="Replace By Everything After It">haha</a>
导致:
test = Replace;
更新:
关键字是一个尚未确定的词,将包含在所有标题中。在这个例子中,它是“By”。
Roko 和 user1215106 的答案都有效——他们从示例中删除了所有多余的部分,留下了 Replace,但我未能澄清关键字之前的短语(在本例中为 Replace)会有所不同,并且会有不同数量的单词。
例如:
title="Replace By Everything After It"
Result= Replace
title="All This Should Stay By Things That Should Go"
Result= AllThisShouldStay
【问题讨论】:
-
“关键字”是什么意思?
-
是否要检索标题属性的第一个单词作为字符串?
-
mvbl fst:澄清后解释。 Sime Vidas:有点,上面澄清了
标签: jquery regex replace character