原网址为http://mysite.com/locations.aspx 当有人单击某处的“位置”链接并进入此页面时,在页面加载时,我希望按如下方式即时附加 URl?医院是页面上的一个复选框,默认需要选中。因此,当他们登陆页面时,他们会看到所有医院,而不必选中医院复选框并重新加载页面。使用 jquery 可以吗?
http://mysite.com/locations.aspx?k= (“医院”)
Find locations by <input name="Keyword" type="text" size="70"/><input name="Search" type="submit" value="Search"/><br/><br/>
Hospitals<input name="Hospitals" type="checkbox" value="Hospital"/>  
Offices<input name="Office" type="checkbox" value="Office"/>  
Emergency Centers<input name="EmergencyCenters" type="checkbox" value="Emergency"/> 
Out-Patient Centers<input name="Out-Patient" type="checkbox" value="Out-Patient"/> 
Facilities<input name="Facility" type="checkbox" value="Facility"/>
最佳答案
您可以创建(在页面 http://mysite.com/locations.aspx 内)类似的函数:
function getDefault() {
var trail = '?k=("Hospital")';
var url = "http://mysite.com/locations.aspx" + trail;
window.location = url;
}
并添加 onload
到<body>
标签如
<body onload="getDefault();">
当然,它会重新加载页面(无需用户干预),但会使用新的尾随参数。
...对于复选框,可以添加适当的属性
$(document).ready(function() {
$("input[name=Hospitals]").attr('checked','checked');
}); // ready
并且它将被即时检查。
关于jquery - 在页面加载时将查询字符串添加到 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9437684/