开发者

If Not A HREF Javascript then what [e.g. mobile phones]

Re:

Which "href" value should I use for JavaScript links, "#" or "javascript:void(0)"?

I am playing with a list of items I am sending from mysql via php o the browser.

In the browser I want to be able to say "Edit this record here".

I want to be able to use on desktop and on my phone.

The issue is that my phone allows me to navigate [give focus to] links, form buttons, form input fields etc but not say icon images. [Not a touch screen phone]

So if I don't use A HREF to pick u开发者_C百科p a focusable point for onclick events then what?

Thanks


It would be best to use an image button for input:

<input type="image" src="someimage.gif" alt="Some Image" onclick="yourFunction()" />

Alternatively, you could also use this form of <a>:

<a href="javascript:yourFunction()">Some Link</a>


The gist of the answers to that question isn't that you should never use anchors as sources of events you intend to handle in JavaScript, just that the anchors should be functional if JavaScript is disabled.

If your app won't work at all with JavaScript disabled, then I wouldn't worry about it and would just use the shortest thing, e.g. #. (Remember to cancel the default action when handling the event, so the page doesn't scroll back to the top.)

But if you can make your app somewhat functional when JavaScript is disabled, that would be even better. Whether that's feasible will depend on your app. For instance, barring other complexities, your "edit this record" link could, with JavaScript disabled, take you to a whole other page for editing the record — but if JavaScript is enabled, you intercept the click and do an in-place edit, that kind of thing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜