javascript - anchor 标签和检查输入

标签 javascript html css

以下是我要实现的目标的简化版本。

基本上,有链接,当它被点击时,它会转到不同页面上的 anchor 标记。这部分有效:)

当到达其他页面 anchor 时,我希望自动勾选复选框。想知道你会怎么做。

想法是,有一个菜单,我希望在 anchor 标记访问它时展开/选中该列表项。

JSFIDDLE

<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/

相关文章:

javascript - 在 React Native 的 ScrollView 中设置 contentInset 和 contentOffset

JavaScript 对象丢失跨函数的引用

html - 如何将侧边栏滑出 View 并调整内容 flexbox 的大小以填充空白?

javascript - 如何将默认的美国男性声音更改为英国女性或其他声音

javascript - 根据 div 内的文本更改 div 背景颜色

html - 如何添加溢出: hidden and max widths on images

javascript - 使用 getElementsByClass 时无法更改类

javascript - 如何获取我的整个 YouTube 观看历史记录?

javascript - clientWidth 和 clientHeight 返回 0

jquery - 添加带有 Append 的 DIV,但没有 CSS 样式