以下是我要实现的目标的简化版本。
基本上,有链接,当它被点击时,它会转到不同页面上的 anchor 标记。这部分有效:)
当到达其他页面 anchor 时,我希望自动勾选复选框。想知道你会怎么做。
想法是,有一个菜单,我希望在 anchor 标记访问它时展开/选中该列表项。
<a href="#sample">click here</a>
<a id="sample"></a>
<input type="checkbox" />
<label for="sample">Sample</label>
最佳答案
使用 JQuery:
<a id="sample" href="#">click here</a>
<input type="checkbox" />
<label for="sample">Sample</label>
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script type="text/javascript">
$('#sample').click(function(e){
$(this).next().prop( "checked", true );
});
</script>
这对我有用。
关于javascript - anchor 标签和检查输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32628028/