Html 单击时如何将href设置为复选框?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17269069/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set href to a checkbox on click?
提问by SAGAR MANE
1.How to set href to a checkbox on click
1.如何在点击时将href设置为复选框
<a href="/Demo/sense/show/4">
<input type="checkbox" />Yes
</a>
<a href="/Demo/sense/list">
<input type="checkbox" />NO
</a>
But when i checked a checkbox.. it not going to another page..
但是当我选中一个复选框时..它不会转到另一个页面..
2.how to set checked on click on YEStext rather than Yes CheckboxPlease Help me.. Thanx
2.如何设置选中点击是文本而不是是复选框请帮帮我..谢谢
回答by
<input type="checkbox" onclick='window.location.assign("/Demo/sense/show/4")'/>Yes
<input type="checkbox" onclick='window.location.assign("/Demo/sense/show/4")'/>Yes
回答by super
Maybe something like this?
也许是这样的?
<input id="cb" type="checkbox" onchange="window.location.href='http://google.com/'">
And then maybe a label for it too:
然后也可能是它的标签:
<label for="cb">Yes</label>
回答by Moeed Farooqui
Just make your code simple:
只需让您的代码简单:
<input type="checkbox" id="chk1" />Yes
<input type="checkbox" id="chk2" />NO
<script type="text/javascript">
$(document).ready(function(){
$('#chk1').click(function(){
window.location='http://www.yahoo.com'; // link of your desired page.
});
});
</script>