Javascript onclick链接文本更改 [英] Javascript onclick link text change

查看:138
本文介绍了Javascript onclick链接文本更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个新页面,对于移动版本,我将进行导航切换以隐藏和显示导航。

I'm working on a new page and for the mobile version I'm going to make a navigation toggle in order to hide and to show the navigation.

HTML代码:

<div id="toogleNavigation">
    <a onclick="toggle_visibility('nav_header','nav_header_level2');">Navigation Einblenden</a>
</div>

Javascript代码:

function toggle_visibility(id, id2) {
    var e = document.getElementById(id);
    var f = document.getElementById(id2);
    if(e.style.display == 'block' || 
       e.style.display == 'block' && 
       f.style.display == 'block') {
        e.style.display = 'none';
        f.style.display = 'none';
        document.getElementById('toogleNavigation').innerHTML = "Navigation 1einblenden";
    } else {
        e.style.display = 'block';
        f.style.display = 'block';
        document.getElementById('toogleNavigation').innerHTML = "Navigation 2ausblenden";
    }
}

我试过:

document.getElementById('toogleNavigation').innerHTML = "Navigation 2ausblenden";

按下链接时更改文本Navigation Einblenden中的文字,但这不是有人有想法吗?

to change the text in text "Navigation Einblenden" when pressing on the link, but this doesn't work... Does somebody has an idea?

推荐答案

将id从div移到a。

Moved the id from div to the a.

查看它在jsbin中工作 http://jsbin.com/eqeheb/5 /观看

See it working in jsbin http://jsbin.com/eqeheb/5/watch

< div> < a id =toogleNavigationonclick =toggle_visibility('nav_header','nav_header_level2');> Navigation Einblenden< / a> < / div>

这篇关于Javascript onclick链接文本更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆