How to use JQuery to truncate the contents of option tags?
Please take a look here: http://www.binarymark.com/Products/FLVDownloader/order.aspx
What I am trying to do is to get rid of the prices inside the option tag. On that page you can see a drop-down box under Order Information, Product. I want to remove the开发者_StackOverflow prices from all the options that contain them in that box, so get rid of " - $75.98" for example. I am not used to JQuery, but I realize it would be possible - just not sure how to do it, so your help would be greatly appreciated.
Thanks. George
Something like this should do the trick:
$('select[name="contractId"] > option').each(function ()
{
var $this = $(this);
$this.text($this.text().split(/\s-/)[0]);
});
That should split the text into an array with the "wanted" part as index 0, and set the text to whatever is contained in that index. You could also use a replace regex if you wanted to.
It would make more sense to do this server-side really, if a user has JS disabled on their machine you could run into problems with displaying incorrect prices.
Unfortunately based on your country of origin, Plimus is not allowed to continue this process. So I cant help you! :)
but this is the general idea:
if ($('#field > div.field-item:contains("someText")').length > 0) {
$("#somediv").addClass("thisClass");
}
精彩评论