我有一个onclick函数,希望可以按它来重置另一个HTML元素(在这种情况下为按钮ID)
function reset(button) {
button.id = "1";
document.getElementById("button.id").innerHTML = button.id;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<!-- close button -->
<button class="btn btn-secondary" onClick="reset();" data-dismiss="modal">
Close
</button>
<!-- close button end -->
<!-- add to cart button -->
<button type="button" onClick="add_price(this); add_image(this);/*reset(this)*/ ;" id="1" class="addtocart btn-primary">
Add to cart
<i class="fas fa-cart-plus ml-2" aria-hidden="true"></i>
</button>
<!-- add to cart button end -->
/*reset(this)*/
有效,但不足,因为每次我将商品添加到购物车时都会重置。在这种情况下,我想使用退出按钮(第一个按钮)退出模态时重置ID。
有什么方法可以使用reset("button.id")
重置添加到购物车按钮?或类似的东西?
通过JQuery:
$('.btn-secondary').attr('id', 'newID')
通过Javascript
document.getElementByClassName(".btn-secondary").id = "newid";