它如何让单选按钮传递数据对 url 隐藏?
How do it have a radio button pass data hidden from url?
事情是这样的,我必须展示一个概念证明,其中我:
使用 url 部分将数据从一个页面传递到另一个页面,并显示在另一个页面中传递的数据。
在页面之间传递数据 NOT 使用 url 部分并显示在另一页传递的数据。
意思是我希望其中一个单选按钮表现为:输入类型="hidden",
但我不知道该怎么做,为了澄清下面有一段代码。任何帮助表示赞赏。澄清一下,它不应该在查询字符串中显示单选按钮的值。
<form method="POST" action="Confirm.jsp">
<p>
Choose:
<input type="radio" checked name="QuizType" value="Private">Private
<input type="radio" name="QuizType" value="Public">Public
<br>
<input type="submit" name="submit" value="submit">
</p>
</form>
您的表单:
<form id="frm1">
<p>
Choose:
<input type="radio" checked name="QuizType" value="Private" id="radio">Private
<input type="radio" name="QuizType" value="Public">Public
<button onclick="myFunction()">Click</button>
</p>
</form>
然后你可以用JavaScript得到选择的值:
function myFunction() {
var radios = document.getElementsByName('QuizType');
for (var i = 0, length = radios.length; i < length; i++) {
if (radios[i].checked) {
// Store the value for the selected radio
// You can maybe redirected on another page and pass this variable
$selectedRadio = radios[i].value
alert($selectedRadio);
break;
}
}
}
勾选这个Example。
如果你想将变量传递给 url 那么你应该尝试:
window.location.href+'/'+$selectedRadio;
资源:
Get Radio Button Value with Javascript, Is there a way to pass javascript variables in url?, How to redirect to another webpage in JavaScript/jQuery?
事情是这样的,我必须展示一个概念证明,其中我:
使用 url 部分将数据从一个页面传递到另一个页面,并显示在另一个页面中传递的数据。
在页面之间传递数据 NOT 使用 url 部分并显示在另一页传递的数据。
意思是我希望其中一个单选按钮表现为:输入类型="hidden", 但我不知道该怎么做,为了澄清下面有一段代码。任何帮助表示赞赏。澄清一下,它不应该在查询字符串中显示单选按钮的值。
<form method="POST" action="Confirm.jsp">
<p>
Choose:
<input type="radio" checked name="QuizType" value="Private">Private
<input type="radio" name="QuizType" value="Public">Public
<br>
<input type="submit" name="submit" value="submit">
</p>
</form>
您的表单:
<form id="frm1">
<p>
Choose:
<input type="radio" checked name="QuizType" value="Private" id="radio">Private
<input type="radio" name="QuizType" value="Public">Public
<button onclick="myFunction()">Click</button>
</p>
</form>
然后你可以用JavaScript得到选择的值:
function myFunction() {
var radios = document.getElementsByName('QuizType');
for (var i = 0, length = radios.length; i < length; i++) {
if (radios[i].checked) {
// Store the value for the selected radio
// You can maybe redirected on another page and pass this variable
$selectedRadio = radios[i].value
alert($selectedRadio);
break;
}
}
}
勾选这个Example。
如果你想将变量传递给 url 那么你应该尝试:
window.location.href+'/'+$selectedRadio;
资源: Get Radio Button Value with Javascript, Is there a way to pass javascript variables in url?, How to redirect to another webpage in JavaScript/jQuery?