我试图在下拉列表中选择将文本值传递给函数的选项,获取它的值,然后选择具有该值的选项。你能明白为什么这不起作用吗?
function selectAndAddToCart(value)
{
console.log('The selectAndAddToCart onclick value is ' + value);
var optionToSelect = $j('#attribute136').find('option[text="' + value + '"]').val(); //select the option with the node text that equals value
//select the option with the node text that equals value
var vals = $j('#attribute136').val() || [];
vals.push(optionToSelect);
$j('#attribute136').val(vals);
//initiate add to cart function
productAddToCartForm.submit(this);
}