答案 0 :(得分:1)
你可以使用jQuery。
<强> HTML 强>
<a href="#" class="button add_to_cart_button product_type_simple added" >Add to Cart</a>
<a href="#" class="button add_to_cart_button product_type_simple added" >Add to Cart</a>
<a href="#" class="button add_to_cart_button product_type_simple added" >Add to Cart</a>
<a href="#" class="button add_to_cart_button product_type_simple added" >Add to Cart</a>
<强>的jQuery 强>
$(document).ready(function() {
$('.add_to_cart_button').on('click', function() {
$(this).text('success').css('color', 'red');
})
})
答案 1 :(得分:0)
您可以使用jQuery尝试。
$(".add_to_cart_button").on("click",function(){
$(this).css("color","red");
$(this).html("Success");
});
&#13;
.button.add_to_cart_button.product_type_simple.added {
color:yellow;
}
&#13;
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<a href="#" class="button add_to_cart_button product_type_simple added">Add to Cart</a>
<a href="#" class="button add_to_cart_button product_type_simple added">Add to Cart</a>
<a href="#" class="button add_to_cart_button product_type_simple added">Add to Cart</a>
<a href="#" class="button add_to_cart_button product_type_simple added">Add to Cart</a>
&#13;
答案 2 :(得分:0)
由于Woocommerce支持jQuery,你可以做这样的事情,如果你不必,不要使用简单的Javascript:
$(function() {
$('.add_to_cart_button').click(function(){
$(this).text('success').css('color', 'red');
});
});
答案 3 :(得分:0)
在纯JavaScript中,你可以用
来完成 1)将onclick="birds()"
更改为onclick="birds(this)"
2)在Birds
函数中,接收锚作为参数并更改锚的样式,而不是遍历所有锚点。
function birds(btn){
btn.style.color = "pink";
btn.innerHTML="Success";
setTimeout ( function() {
cats(btn);
}, 2000 );
}
function cats(btn){
btn.style.color = "red";
btn.innerHTML="Add to Cart";
}
&#13;
.button.add_to_cart_button.product_type_simple.added {
color:yellow;
}
&#13;
<a href="#" class="button add_to_cart_button product_type_simple added" onclick="birds(this)">Add to Cart</a>
<a href="#" class="button add_to_cart_button product_type_simple added" onclick="birds(this)">Add to Cart</a>
<a href="#" class="button add_to_cart_button product_type_simple added" onclick="birds(this)">Add to Cart</a>
<a href="#" class="button add_to_cart_button product_type_simple added" onclick="birds(this)">Add to Cart</a>
&#13;
答案 4 :(得分:0)
我想提供一种本地方式:
var all_buttons = document.querySelectorAll(".add_to_cart_button");
Array.prototype.slice.call(all_buttons)
.forEach(function(button) {
button.onclick = function() {
this.innerHTML = 'success';
this.style.color = 'red';
};
});
.button.add_to_cart_button.product_type_simple.added {
color:yellow;
}
<a href="#" class="button add_to_cart_button product_type_simple added">Add to Cart</a>
<a href="#" class="button add_to_cart_button product_type_simple added">Add to Cart</a>
<a href="#" class="button add_to_cart_button product_type_simple added">Add to Cart</a>
<a href="#" class="button add_to_cart_button product_type_simple added">Add to Cart</a>