繁体   English   中英

当在javascript中单击复选框时如何将复选框的值添加到url

[英]how to add valaue of checkbox to url when checkbox clicked in javascript

<input class="messageCheckbox" type="checkbox" name="options[]" value="<?php echo $catrecord[0] ; ?>"/>

这是复选框,当有人选择它时,我想转到另一个URL,其中URL为复选框,而不是帖子。

这是我想在复选框后添加'case new'的地方:

window.location = '<?php echo JURI::base()."index.php?option=com_flatorb&view=entity"?>';
break;

您可以将更改事件处理程序与复选框绑定,并使用window.location打开页面。

$('#checkboxId').change(function(){
   if(this.checked)
      window.location = 'index.php?option=com_flatorb&view=entity&chkValue=' + this.value;
});
document.[name of form].[name of checkbox].checked

或使用jQuery:

$('#[id of checkbox]').is(':checked');

您可以执行以下操作

方法1

$('.messageCheckbox').change(function(){
   if(this.checked)
      window.location = 'index.php?option=com_flatorb&view=entity&value=' + $(this).val('');
});

方法2

$('.messageCheckbox').change(function(){
   if($('#edit-checkbox-id').is(':checked'))
      window.location = 'index.php?option=com_flatorb&view=entity&value=' + $(this).val('');
})

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM