Php 将url绑定到复选框值
我有一个复选框,我想用作语言开关:Php 将url绑定到复选框值,php,html,url,checkbox,Php,Html,Url,Checkbox,我有一个复选框,我想用作语言开关: <label class="switch"> <input type="checkbox" class="switch-input"> <span class="switch-label" data-on="DE" data-off="FR"></span> <span class="switch-handle"></span> </label>
<label class="switch">
<input type="checkbox" class="switch-input">
<span class="switch-label" data-on="DE" data-off="FR"></span>
<span class="switch-handle"></span>
</label>
我有一个index.php
文件,如果添加?lang=de
,内容的语言将更改为德语;如果添加?lang=fr
,内容的语言将更改为法语。现在是否可以将每个URL绑定到复选框值之一?例如,如果未选中复选框,则参数?lang=de
,如果选中,则参数?lang=fr
将添加到URL中,并显示此语言的内容?尝试-
var param = "lang=de";
$('.switch-input').on('click', function() {
if($(this).is(':checked')) {
param = "lang=" + $(this).siblings('.switch-label').data('on');
} else {
param = "lang=" + $(this).siblings('.switch-label').data('off');
}
window.location.href = window.location.href + '?' + param;
})
在执行此操作时,
param
变量不包含对url的查询,而是包含url本身。window.location.href
应该是window.location.href='?'+param
。谢谢您的回答。遗憾的是,我有点困惑如何将其包含到我的php文件中。我试图将您的代码添加到…
中,但没有成功。以及在何处定义var param=“lang=de”代码>?有人能帮我吗?谢谢。我没有导入jQuery。