使用href在HTML中传递参数

使用href在HTML中传递参数,html,href,Html,Href,我可以使用html中的以下行传递带有链接的静态值 <button class="light" id = "pg1" onclick="window.location.href = '1.html?theme=light';">page 1</button> 第1页 这里我添加了?theme=light,以便以后可以在1.html中检索theme的值 我的问题:是否有方法发送类变量本身 i、 e,如果class=“dark”有没有一种方法可以将主题作为发送?theme=

我可以使用html中的以下行传递带有链接的静态值

<button class="light" id = "pg1" onclick="window.location.href = '1.html?theme=light';">page 1</button>
第1页
这里我添加了
?theme=light
,以便以后可以在
1.html中检索
theme
的值

我的问题:是否有方法发送类变量本身


i、 e,如果
class=“dark”
有没有一种方法可以将主题作为
发送?theme=dark
,而不必自己更改参数?

您必须使用JS函数读取当前对象的类(您已经在onClick事件中使用JavaScript):


功能设置链接(obj){
window.location.href='1.html?主题='+obj.className;
}
第1页

您必须使用JS函数读取当前对象的类(您已经在onClick事件中使用JavaScript):


功能设置链接(obj){
window.location.href='1.html?主题='+obj.className;
}
第1页

您不能使用javascript有什么原因吗?您不能使用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>