Javascript onclick复选框事件

Javascript onclick复选框事件,javascript,jquery,query-string,Javascript,Jquery,Query String,我所要做的就是点击复选框,将其值附加到URL并重定向..我该怎么做 $(document).ready(function() { var url = 'http://mysite.com/results.aspx'; $('.LocType').click (function () { var thisCheck = $(this); if (thischeck.is (':che

我所要做的就是点击复选框,将其值附加到URL并重定向..我该怎么做

$(document).ready(function() {   
    var url = 'http://mysite.com/results.aspx';   
        $('.LocType').click (function ()
            {
                var thisCheck = $(this);
            if (thischeck.is (':checked'))
             {
            // Do stuff
             window.location.href = "http://www.yahoo.com";  

             }
        });
}); 

<div class="MyOptions"> 
    Hospitals<input class="LocType" type="checkbox" value="Hospital"/> &#160;  
    Offices<input class="LocType" type="checkbox" value="Office"/> &#160;  
    Facilities<input class="LocType" type="checkbox" value="Facility"/> 
</div> 
$(文档).ready(函数(){
var url='1〕http://mysite.com/results.aspx';   
$('.LocType')。单击(函数()
{
var thisCheck=$(此);
if(thischeck.is(':checked'))
{
//做事
window.location.href=”http://www.yahoo.com";  
}
});
}); 
医院 家;
办公室 个;
设施

这确实不是一个好的UI设计-用户不希望通过复选框进行导航-但下面是您想要的代码:

$('.LocType').click (function () {
   if (this.checked) {
       // Do stuff
       window.location.href = "http://www.yahoo.com?paramNameHere=" + this.value;
   }
});
您不需要在函数中使用
$(this)
,因为
this
足以检查
checked
状态并获取


您没有说明生成的URL应该是什么样子,所以我只是在该值后面附加了一个通用的
paramname here
参数。

如果您将函数设置为接收一个参数,javascript将为您提供一个事件,该事件具有触发该事件的元素,您可以将其存档到下一个代码:

$('.LocType').click (function (e) {
   if (this.checked) {
       // Do stuff
       window.location.href = "http://www.yahoo.com" + e.target.value;
      //e.target is the element that fire up the event
   }
});

你在尝试导航吗?如果是这样的话,你可能会想重新考虑一下——这是非常难以实现的。