單擊按鈕時,我嘗試向 CSS 添加類,它在桌面上有效,但在手機上無效
這是我的代碼:
<script>
document.getElementById('logbit').addEventListener('click',function() {
document.getElementById('logf').classList.add('bg');
})
</script>
uj5u.com熱心網友回復:
如果您沒有在代碼中使用 jquery,我不知道您為什么要使用 jquery 標記。
但是既然你問到 jquery 我會給出一個 jquery 的答案。
$("#logbit").click(function() {
$("#logf").addClass("bg");
})
那應該可以在手機和PC上使用。
uj5u.com熱心網友回復:
看看這是否有效:
<style>
.bg {
background-color: blue;
}
</style>
<input type="button" value="Button" id="button">
<script>
document.querySelector("#button").onclick = function () {
document.body.classList.add("bg");
}
</script>
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/422545.html
標籤:
