简体   繁体   中英

javascript taking # marker literally

I have some code on some of my links

<a class="nav_bu" onclick="switchType('all'); return false;" href="#">

when I click on them, I get fowarded to mydomain.com/# (404 error..).

How can I get the function activated, rather then the href link.

PS I have mod_rewrite running, is this screwing things up? Here are the rules that effect the root directory:

RewriteRule ^home/$ home.php [L]
RewriteRule ^inbox/$ inbox/inbox.php [L]

I think you have an error in the switchType('all') function. That is why the browser does not get to return false; and uses the default action to redirect you to href .

使用按钮代替链接

First of all, you state, based on your tags, that you are using jQuery. Why would you be using inline javascript listeners then?

Try this:

$(function() {
    $('.nav_bu').click(function() {
        switchType($(this).attr('rel'));
        return false;
    });
});

If this is your HTML:

<a class="nav_bu" rel="all" href="#">Blah Blah</a>

But, yeah... like people are saying, you probably have a problem with your switchType function. Run the site in Firefox with Firebug installed and it should tell your right where you problem is.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM