我正试图禁用我网站上的一个按钮。我的JavaScript在控制台中工作:
list = document.getElementsByClassName("single_add_to_cart_button button alt");
list[0].disabled = true;
但将其添加到页面中并不起作用:
add_action( 'wp_head', function () { ?>
<script>
list = document.getElementsByClassName("single_add_to_cart_button button alt");
list[0].disabled = true;
</script>
<?php } );
我还尝试等待加载对象:
add_action( 'wp_head', function () { ?>
<script>
list = document.getElementsByClassName("single_add_to_cart_button button alt");
list[0].addEventListener("load", disable);
function disable() {
list = document.getElementsByClassName("single_add_to_cart_button button alt");
list[0].disabled = true;
};
</script>
<?php } );
here