I'm attempting to do the following. I need to "grab" the value found in a specific list item, then assign it to a variable name, and then use that variable in a few other places in the code.
Here's what I'm trying to do specifically line by line. I need to get the Category value from the following list item.
<li class="fc_cart_item_option fc_cart_category_code">Category: SHIP6</li>
In this case the value I'm trying to get is "SHIP6". The values will be either "SHIP1" through "SHIP9" (i.e. SHIP1, SHIP2, SHIP3, etc. up to SHIP9) and that's it. Then if the value is equal to "SHIP1", I need to assign a value to a variable (I'm assuming). If the value is "SHIP1", I'd like to have the variable equal to "1.00", if "SHIP2", the variable's value "2.00", if "SHIP3", the variable's value "3.00", and so on up to 9. If I don't need to store it as a variable, please let me know. But at this point I'm assuming I do. So for the sake of this discussion, we'll call it "variable_category_ship". So now that we've assigned the value to this variable (variable_category_ship), I need to then do the following.
Further down in the code I have this line of jQuery:
$('#fc_cart_foot_total').before("<tr id='fc_cart_foot_tax'><td class='fc_col1' colspan='2'>Sales Tax:</td><td class='fc_col2'>$0.00</td></tr><tr id='fc_cart_foot_shipping'><td class='fc_col1' colspan='2'>Shipping:</td><td class='fc_col2'>$4.00</td></tr>");
I need to replace "4.00" with the variable amount we create from above. So I'm imagining it will now be the following:
$('#fc_cart_foot_total').before("<tr id='fc_cart_foot_tax'><td class='fc_col1' colspan='2'>Sales Tax:</td><td class='fc_col2'>$0.00</td></tr开发者_JAVA技巧><tr id='fc_cart_foot_shipping'><td class='fc_col1' colspan='2'>Shipping:</td><td class='fc_col2'>$(variable_category_ship)</td></tr>");
So to confirm, if:
<li class="fc_cart_item_option fc_cart_category_code">Category: SHIP5</li>
Then:
$('#fc_cart_foot_total').before("<tr id='fc_cart_foot_tax'><td class='fc_col1' colspan='2'>Sales Tax:</td><td class='fc_col2'>$0.00</td></tr><tr id='fc_cart_foot_shipping'><td class='fc_col1' colspan='2'>Shipping:</td><td class='fc_col2'>$5.00</td></tr>");
How would I go about doing this? Thanks!
Try this:
var val = $("li.fc_cart_category_code").text();
val = "$" + val.replace(/[^0-9]/g, "") + ".00";
$('#fc_cart_foot_total').before("<tr id='fc_cart_foot_tax'><td class='fc_col1' colspan='2'>Sales Tax:</td><td class='fc_col2'>$0.00</td></tr><tr id='fc_cart_foot_shipping'><td class='fc_col1' colspan='2'>Shipping:</td><td class='fc_col2'>" + val + "</td></tr>");
精彩评论