【发布时间】:2012-02-06 12:11:11
【问题描述】:
我想从现有字符串中删除通配符字符串,然后将其附加到 div 之后。
在我的例子中,我想从一个字符串中找到一个零件号,然后将该字符串设置为一个变量。
所以不是这个(请注意 [] 之间可以是任何东西):
<div> The part number is [8F8S0JJ9]</div>
<div> The second part number is [V9S7D73]</div>
我会的:
<div> The part number is</div>
[8F8S0JJ9]
<div> The second part number is</div>
[V9S7D73]
这是我的代码:
// Get the product number that lies between [ ] marks from all div elements
$('div:contains('['+*+']')').html(function() {
//Look for the wildcard string and save it to a variable. how can I search within the string?!
var $finalstring = $(this).search('['+*+']');
//remove it from the string
$(this).replace($finalstring, '');
//Set it to display after the string
$(this).append($finalstring);
});
谢谢
【问题讨论】:
-
通配符字符串会一直是句子中的最后一个单词吗?
标签: jquery string append wildcard