我有一个具有两种可能类型(“ id”或“ profile”)的HTML表单
<form action="process.php">
<input type="radio" name="type" value="id">
<input type="radio" name="type" value="profile">
<input type="text" name="value" value="input">
</form>
所以从本质上讲,我得到的URL是
/process.php?type=id&value=input
(或type = profile,取决于用户选择的内容)
我想要的是我的网址看起来像
/process.php?id=input
要么
/process.php?profile=input
我有两个问题:
1)以下jQuery / JavaScript代码是否“不好用”? 如果按以下方式进行操作,我确实感觉不正确(即使可行):
<input type="submit" onclick="formSubmit()">
<script>
function formSubmit() {
// if the first radio (id) is selected, set value name to "id", else "profile"
$("form input:text")[0].name = $("form input:radio")[0].checked ? "id" : "profile";
// disable radio buttons (i.e. do not submit)
$("form input:radio")[0].disabled = true;
$("form input:radio")[1].disabled = true;
}
</script>
2)有没有一种方法可以不使用htaccess规则或JavaScript?
谢谢!