admin管理员组文章数量:1313170
How can I change each labels first character except the last labels character $ sign to £ using jQuery?
Here is the code:
<p align="center" id="myradio">
<label>$25.00 </label>
<input checked="checked" class="hide_input" name="amount" type="radio" value="25.00" />
<label>$50.00</label>
<input class="hide_input" name="amount" type="radio" value="50.00" />
<label>$100.00</label>
<input class="hide_input" name="amount" type="radio" value="100.00" />
<label>$250.00</label>
<input class="hide_input" name="amount" type="radio" value="250.00" />
<label>$500.00</label>
<input class="hide_input" name="amount" type="radio" value="500.00" />
<label>$1000.00</label>
<input class="hide_input" name="amount" type="radio" value="1000.00" />
<label>other amount</label>
<input class="show_input" id="other" name="amount" type="radio" value="" />
</p>
How can I change each labels first character except the last labels character $ sign to £ using jQuery?
Here is the code:
<p align="center" id="myradio">
<label>$25.00 </label>
<input checked="checked" class="hide_input" name="amount" type="radio" value="25.00" />
<label>$50.00</label>
<input class="hide_input" name="amount" type="radio" value="50.00" />
<label>$100.00</label>
<input class="hide_input" name="amount" type="radio" value="100.00" />
<label>$250.00</label>
<input class="hide_input" name="amount" type="radio" value="250.00" />
<label>$500.00</label>
<input class="hide_input" name="amount" type="radio" value="500.00" />
<label>$1000.00</label>
<input class="hide_input" name="amount" type="radio" value="1000.00" />
<label>other amount</label>
<input class="show_input" id="other" name="amount" type="radio" value="" />
</p>
Share
Improve this question
edited Apr 26, 2012 at 16:36
noob
9,2124 gold badges39 silver badges65 bronze badges
asked Apr 26, 2012 at 16:32
user1235905user1235905
1457 bronze badges
1
- Your last label doesn't have any instance of the $ sign. – Sampson Commented Apr 26, 2012 at 16:37
4 Answers
Reset to default 12You can use the internal looping to swap the characters:
$("#myradio label").html(function(){
return this.innerHTML.replace( '$', '£' );
});
$("#myradio label:not(:last)").each(function() {
$(this).text($(this).text().replace(/^\$/, "£"));
});
$('#myradio label').each(function() {
$(this).text('£' + $(this).text().substr(1));
});
This basically takes the substring of the label, beginning from the first character (till the end) - which is the text without the $ symbol. And appends it to the pound symbol. This concatenated text is used tot replace the existing text.
$('#myradio label').html(function() {
return this.innerHTML.replace(/^\$/,'£');
});
本文标签: javascriptReplace first character inside the labelStack Overflow
版权声明:本文标题:javascript - Replace first character inside the label - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741930500a2405546.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论