0
頁面加載的URL爲http://mysite.aspx/result.aspx?k=(「Hospital」)。 現在頁面加載後,如果有人選擇辦公室複選框,它應該是複選框「辦公室」的URL的值追加爲 http://mysite.aspx/result.aspx?k=(「醫院」或「辦公室」)onselect複選框將所選值添加到URL中作爲查詢字符串
如何在jQuery的做到這一點?
<div class="LocationSearchBox">
<input name="KeywordBox" class="BasicSearchInputBox" type="text" value="Type a Keyword.."/>
<div class="searchBtnHolder"><a class="searchButton" href="#" type="submit"><span>Search</span></a></div>
</div>
<br/><br/>
<div class="MyOptions">
Hospitals<input name="LocType" type="checkbox" value="Hospital"/>  
Offices<input name="LocType" type="checkbox" value="Office"/>  
Emergency Centers<input name="LocType" type="checkbox" value="Emergency"/> 
Out-Patient Centers<input name="LocType" type="checkbox" value="Out-Patient"/> 
Facilities<input name="LocType" type="checkbox" value="Facility"/>
</div>
<script type="text/javascript" language="javascript">
$(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;
});
}):
});