在我的主页(网络表单(上,我有 3 个单选按钮可供选择。如何设置超链接的格式以将用户定向到该页面并自动选择单选按钮?
<div class="col-lg-3">
<asp:RadioButtonList ID="rdbtnChoise" Font-Size="11" ToolTip="Select a service: A description of the service is listed under each title once selected." runat="server" OnSelectedIndexChanged="rdbtnChoise_SelectedIndexChanged" AutoPostBack="True">
<asp:ListItem Value="1" Text="G1"> OPTION 1</asp:ListItem>
<asp:ListItem Value="2" Text="G2"> OPTION 2</asp:ListItem>
<asp:ListItem Value="3" Text="G3"> OPTION 3</asp:ListItem>
</asp:RadioButtonList> </div>
我想设置一个超链接以自动选择第一个单选按钮。我尝试过阅读其他类似的问题,但似乎都没有奏效。
假设我的网页是:https://examplesite.com
从您的问题来看,您的问题是如何提供指向页面的链接,当用户浏览该链接时,将在呈现后检查第一个单选按钮
如果我的理解是正确的
你可以使用 JS 来实现这一点
假设你包含了jQuery。
在单选按钮页面上,在下面添加
<script>
$(function(){
var isCheck = getParameterByName("isCheckRadio") === 'true';
if(isCheck){
$('input:radio[name="rdbtnChoise"]').first().prop("checked", true);
}
});
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[[]]/g, "\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/+/g, " "));
}
</script>
这意味着当页面加载时,如果URL有查询字符串isCheckRadio
值作为true
,请检查第一个单选
那么您提供的 URL 将是类似
<a href="https://examplesite.com?isCheckRadio=true">link</a>