我需要使用jQuery獲得幾個選定對象的值,並顯示每個對象的標題,分別...WooCommerce - jQuery的 - Muliple的顯示標題選擇的色板
我使用WooCommerce與變異色板和照片插件。選擇色板時,我想在屬性標題旁邊顯示色板名稱。我發現部分solution,但我需要函數來循環每個類,因爲我有多個色板選項。
從變化色板插件的代碼是
jQuery的在上述解決方案提供的是:
(function($){
"use strict";
$('body').on('change', 'div.select', function(event){
var colorname = "";
var colorname = $(".selected a.swatch-anchor").attr('title');
if(colorname){
$(".variations-table label").html('Color: ">'+colorname);
}else{
$(".variations-table label").html("Please select a color");
}
});
})(jQuery);
該腳本作品,如果你只有一個樣本面板,但我一定要有幾個色板選項。所以我會選擇顏色,大小和方向作爲色板。
我知道我需要在每個類上運行一個函數,但是我的嘗試一直不成功。這是我想出了:
$(function() {
function changeName) {
$("td.attributes_border").each(function(){
var swatchname = "",
swatchname = $(".selected a.swatch-anchor").attr('title');
if(swatchname){
$(".attribute_title_label label").html(+swatchname);
}else{
$(".attribute_title_label label").html("Please select an option");
}
});
$("div.select").on("change", changeName);
changeName();
});
我相信這是很簡單的,但我的JavaScript和jQuery的知識是非常有限的。
感謝