値を分割できませんでした。なぜ(var = amt1)の値にスペースが与えられないのか疑問に思います。したがって、 alert(amt1)
次のような値を取得する 100$200$300$
。私は得ることになっていた 100$ 200$ 300$
.
jQuery(document).ready(function(){
jQuery("#pa_ssl").one("change",function(){
var amt1 = jQuery("form.cart_group").find(".component.paged:eq(0)").find("span.woocommerce-Price-amount.amount").text();
alert(amt1);//i need (100$ 200$ 300$) insteat of (100$200$300$)
var single_amt = amt1.split("Rs.");
var amount1 = single_amt[1];
alert(amount1);
jQuery(".component_inner .composited_product_details_wrapper").append("Rs." + amount1 + "<br/>");
});
});
回答:
回答№1は1呼び出し text()
要素のコレクションでは、スペースなしのDOMにあるため、すべての値が連結されます。それらの配列を作成したい場合は、 map()
代わりに。
jQuery(function($){
$("#pa_ssl").one("change", function(){
var amounts = $("form.cart_group .component.paged:eq(0) span.woocommerce-Price-amount.amount").map(function() {
return $(this).text().replace("Rs.", "");
}).get();
var amount1 = amounts[1];
console.log(amount1);
$(".component_inner .composited_product_details_wrapper").append("Rs." + amount1 + "<br/>");
});
});
回答№2の場合は0
正常に動作しています!
jQuery(document).ready(function(){
jQuery("#pa_ssl").one("change",function(){
var amt1 = jQuery("form.cart_group").find(".component.paged:eq(0)").find(".woocommerce-variation-price span.woocommerce-Price-amount.amount").text();
var single_amt = amt1.split("Rs.");
var amount1 = single_amt[0];
jQuery(".component_inner .composited_product_details_wrapper").append("Rs." +amount1+"<br/>");
});
});