我有一組複選框複選框值頁面刷新後檢查:組複選框基於URL查詢字符串
<input name="LocType" type="checkbox" value="Hospital"/>HOSPITALS  
<input name="LocType" type="checkbox" value="Office"/> PHYSICIAN OFFICES  
<input name="LocType" type="checkbox" value="Emergency"/>EMERGENCY CENTERS  
<input name="LocType" type="checkbox" value="Out-Patient"/>OUT-PATIENT CENTERS  
<input name="LocType" type="checkbox" value="Facility"/>FACILITIES
如下我已經抓住了他們的價值觀和傳遞到URL,可通過重新加載頁面後querystring,我想檢查任何複選框值傳遞和設置複選框檢查=真。
var url = "http://mysite.com/contact-us/Pages/LocationSearch.aspx?s=bcs_locations&k=";
var checkboxValues = $("input[name=LocType]:checked").map(function() {
return ' '+'bcslocationtype:'+"\"" + $(this).val() + "\"";}).get().join(" OR ");
window.location= url + checkboxValues;
當醫院和緊急複選框被選中,並點擊搜索,網址如下: http://mysite.com/contact-us/Pages/LocationSearch.aspx?s=bcs_locations&k= bcslocationtype:「醫院」或bcslocationtype:「緊急」
現在爲什麼不工作的事,我不噸看到什麼錯呢?其insde的document.ready(){}
//Keep the selected chkboxes checked on page redirect
var value = window.location.href.match(/[?&]k=([^&#]+)/) || [];
if (value.length == 2) {
$('input[name=LocType]').each(function (index) {
if(value[1].indexOf($(this).val())>=0)
this.prop("checked", true);
});
}