我可以在html中使用下面这一行来传递一个带有链接的静态值。
<button class="light" id = "pg1" onclick="window.location.href = '1.html?theme=light';">page 1</button>
我在此附上 ?theme=light
的值,这样我以后就可以检索到 theme
在 1.html
我的问题是:有没有办法让我自己发送类变量? 有没有办法让我发送类变量本身?
即 如 class="dark"
有什么办法可以让我把主题作为 ?theme=dark
而不自己修改参数?
你必须使用JS函数读取当前对象的类(你已经在onClick事件中使用了JavaScript)。
<script type="text/javascript">
function setLink(obj){
window.location.href = '1.html?theme=' + obj.className;
}
</script>
<button class="light" id = "pg1" onclick="setLink(this);">page 1</button>