onselect复选框将选定的值作为查询字符串添加到URL

页面加载URL为http://mysite.aspx/result.aspx?k = (“Hospital”)。 现在页面加载后,如果有人选择办公室复选框,它应该将该复选框’Office’的值附加到URL为http://mysite.aspx/result.aspx?k = (“医院”或“办公室”)

我如何在jquery中执行此操作?

 

Hospitals   Offices   Emergency Centers  Out-Patient Centers  Facilities
$(document).ready(function() { var url = 'http://mysite.com/results.aspx?k=("Hospital"); $(".LocationSearchBox a.searchButton").click(function(){ var chkboxVal = $("input[name='LocType']:checked").val(); var keywords = encodeURIComponent($(".BasicSearchInputBox").val()); url =url+"?kwd="+keywords+"&type="+chkboxVal; window.location.href=url; }); }): });

你的代码应该是这样的……

 $(document).ready(function() { var url = 'http://mysite.com/results.aspx'; $(".MyOptions input").click(function() { var urlValues = window.location.href.split("k=(")[1]; urlValues = urlValues.substring(0,urlValues .length - 1); var checkboxValues = $("input[name=LocType]:checked").map(function() {return "\"" + this.value + "\"";}).get().join(" OR ") if (urlValues.length > 0) urlValues += " OR " + checkboxValues; var keywords = encodeURIComponent($(".BasicSearchInputBox").val()); window.location.href = "http://mysite.aspx/result.aspx?k=(" + urlValues + ")"; }); });​