转换错误<span href =“#”>以更正<a href="#">

时间:2017-01-28 09:57:38

标签: css

This code gives errors in the W3 Validator, however it does the job on click.

<span href="#" class="click">+</span>

If I convert it to the code below it validates in the W3 but on click the pointer moves up, on the screen. It does not stay on the "+"

<a href="#" class="click">+</a>

What is wrong with it?

3 个答案:

答案 0 :(得分:3)

如果您不想提供链接,请使用<button>代替<a>

<button>元素正是您想要的,因为<a>标记用于链接,而href="#"会触发跳转到顶部。

答案 1 :(得分:2)

要避免在锚标记上点击跳转,请删除哈希并添加javascript:;,如下所示:

<a href="javascript:;" class="click">+</a>

答案 2 :(得分:0)

你也可以这样使用。

<a href="javascript:void(0)"; class="click">+</a>

您引用了更多here