开发者

Html/Javascript - How to make an html link display a url, and have it actually be redirected to a javascript function?

I have an html page, and I need a link to show that the user would be going to 'example.html', when really, the link goes to 'javascipt:ajaxLoad(example.html);'.

I tried this:

<a href="example" onclick="javascipt:ajaxLoad(example.html);">Example</a>

But it didn't work. Any help? I a开发者_如何转开发lready asked the webmasters stackexchange, and they told me that this would be a javascript programming question. Not an html question.


<a href="example.html" onclick="ajaxLoad(this.href); return false;">Example</a>

By returning false you prevent the default action. And this way the links will still work when javascript is disabled, but then you don't get the AJAX functionality.


Just point the href at the actual file. The javascript onclick will take precedence - as long as you take care to disable the actual click effect by doing a "return false" or similar, the status bar will show 'example.html' and not the javascript url.

As well, note that it should be javascript:... (you're missing an r). The onwhatever attributes are already assumed to be javascript, so you could just say onclick="ajaxLoad(...) anyways.


Look, I'm not sure if I got exactly what you're asking about here, but the following fix often works with me. Just change the double-quotes to single-quotes, and put double-quotes around the example.html part

<a href="example" onclick='javascipt:ajaxLoad("example.html");'>Example</a>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜