[英]how do I check a radio button after being redirected
How can I check a radio button after being redirected to a new web page ? 重定向到新网页后如何查看单选按钮?
I've tried this script : 我已经尝试过以下脚本:
<script>
function AffStatus(choix) {
document.getElementById(choix).checked = true;
document.location.href = "PAGELINK?tri="+ choix;
}
</script>
With these radio buttons 使用这些单选按钮
Sort by : <input type="radio" name="choice" id="ddc" value="ddc"
on="AffStatus('ddc')" checked />Activity
<input type="radio" name="choice" id="di" value="di"
onclick="AffStatus('di')" />Date <input
type="radio" name="choice" id="nm" value="nm"
onclick="AffStatus('nm')" />NBM <input
type="radio" name="choice" id="p" value="p" onclick="AffStatus('p')" />Pseudo
(A-Z)
PS: I'm redirecting the user to the same displayed page. PS:我将用户重定向到相同的显示页面。
EDIT: I'm programming with Java EE using Eclipse not PHP. 编辑:我正在使用Java EE而不是PHP使用Eclipse进行编程。
But it doesn't work for me. 但这对我不起作用。 I think that I've wrote a wrong script that I can't a solution to fix it.
我认为我写了一个错误的脚本,无法解决该问题。 Any help please ?
有什么帮助吗?
Actually there is no need to have separate code to check the radio buttons with same names. 实际上,不需要使用单独的代码来检查具有相同名称的单选按钮。 It will be automatically uncheck other and check the new one.
它将自动取消选中其他并选中新的。
I found a mistake that you have on="AffStatus('ddc')" instead of onclick="AffStatus('ddc')" 我发现您的错误是on =“ AffStatus('ddc')”而不是onclick =“ AffStatus('ddc')”
I wonder why you are not using Jquery, 我想知道为什么您不使用Jquery,
EDITED: 编辑:
since you want to select the radio after refresh and you dont use the backend code to get the URL param 'tri', this function will help you.. 由于您要在刷新后选择无线电,并且您不使用后端代码来获取URL参数“ tri”,因此此功能将为您提供帮助。
function AffStatus(choix) {
document.getElementById(choix).checked = true;
document.location.href = "PAGELINK?tri="+ choix;
}
window.onload=function(){
var selected_radio = getURLParameter('tri');
console.log(selected_radio)
document.getElementById(selected_radio).checked = true;
}
function getURLParameter(name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null
}
Use this function to get tri
value from your link 使用此功能从链接中获取
tri
值
Function : 功能说明
var RequestQuerystring;
(window.onpopstate = function () {
var match,
pl = /\+/g, // Regex for replacing addition symbol with a space
search = /([^&=]+)=?([^&]*)/g,
decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
query = window.location.search.substring(1);
RequestQuerystring = {};
while (match = search.exec(query))
RequestQuerystring[decode(match[1])] = decode(match[2]);
})();
Usage : 用法:
var myTri = RequestQuerystring.tri // your tri from the link
then pass myTri
to your Checked
然后将
myTri
传递给您的Checked
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.