既存の文字列からワイルドカード文字列を削除し、divの後に追加したいと思います。jQueryではどのように特定のワイルドカード文字列を変数に保存しますか?
私の場合、文字列内から部品番号を探して、その文字列を変数に設定したいと考えています。
ので、代わりにこのの([]何もすることができます間に注意してください):
私が持っているでしょう<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);
});
おかげ
ワイルドカード文字列は常に文の最後の単語ですか? – DaveE