Why the handle in JQuery UI slider is <a> tag?

好久不见. 提交于 2019-12-10 13:31:44

问题


I was reading the code in the official demo page for slider: http://jqueryui.com/demos/slider/ and I was wondering why an <a> tag is used for handle? Why not a <div>?

<div class="demo">

<div id="slider" class="ui-slider ui-slider-horizontal ui-widget ui-widget-content ui-corner-all">
    <a class="ui-slider-handle ui-state-default ui-corner-all ui-state-hover" href="#" style="left: 19%; ">
    </a>
</div>

</div>

回答1:


I think they used an anchor because in HTML links are what separate HTML from other markup languages because they provide interaction. Taken from w3c

HTML offers many of the conventional publishing idioms for rich text and structured documents, but what separates it from most other markup languages is its features for hypertext and interactive documents. This section introduces the link (or hyperlink, or Web link), the basic hypertext construct. A link is a connection from one Web resource to another. Although a simple concept, the link has been one of the primary forces driving the success of the Web.

And the handle is also something you click, so maybe they thought that semantically made more sense using an <a> instead of a <span>.

To make it clear, my thought is that they could have used anything technically but they choose an anchor for semantic reasons




回答2:


I was wondering the same ... so here I am ... with a theory!

The handles need to be able to have the focus
(when they do, you can use the arrows, Home- and End-keys to manipulate the handles)

Not sure if spans or divs can have the focus (in all browsers..) ?

Maybe <button> could be used instead ? (somebody, please try)
- that would make more sense. And not clutter up the status-line : (
(Could we get into trouble, if there's a surrounding form without a proper submit-button ?)



来源:https://stackoverflow.com/questions/10010770/why-the-handle-in-jquery-ui-slider-is-a-tag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!