你可以用一点 php 来做到这一点:
<input type="checkbox" name="one" value="one" id="one" <?= ($_GET["one"] == "checked" : "checked" : "" ?> >
<input type="checkbox" name="two" value="two" id="two" <?= ($_GET["two"] == "checked" : "checked='checked'" : "" ?>>
.... 或者正如你提到的,在客户端使用 Javascript:
document.body.onload = function() {
var hash = window.location.hash().substr(1);
var parts = hash.split("&");
for(var i = 0; i < parts.length; i++) {
var variable = parts.split("=");
if(variable[0] == "one") // if the key of a get-variable equals "one"
document.getElementById("one").setAttribute("checked");
else if(variable[0] == "two") // if the key of a get-variable equals "two"
document.getElementById("two").setAttribute("checked");
}
};
我希望它有帮助...