你可以用一个正则表达式来做到这一点:例如
将 KR50 兑换成 50KR
//assign the parent to make things a little readable
parent = $('span.geo_currency').parent();
//swap the span
parent.html(parent.html().replace(/(<span class="geo_currency">.*<\/span>)([\d\.\,]{1,20})/, '$2$1'));
将 50KR 兑换成 KR50
//assign the parent to make things a little readable
parent = $('span.geo_currency').parent();
//swap the span
parent.html(parent.html().replace(/([\d\.\,]{1,20})(<span class="geo_currency">.*<\/span>)/, '$2$1'));
限制
- 我假设您的 HTML 有一个合适的父级,否则扫描 DOM 会很麻烦。
- 你的数字是一个浮点数,< 20 个字符,只有一个点或逗号作为分隔符。
- 这不会是一个句子,句号是一个句子,例如,有了这个,您将获得 KR50。
这是一个工作示例:http: //jsfiddle.net/fEksT/