不同按钮进入同一个页面显示不同的div

页面一的按钮:

<div  style="padding:10px 0px;">
    <a href="#/financialStatements?byYear" class="easyui-linkbutton l-btn l-btn-large" style="width:200px;height:45px;display:inline-block;">纳税报表</a>
    <a href="#/financialStatements?debet" class="easyui-linkbutton l-btn l-btn-large" style="width:200px;height:45px;display:inline-block;">资产负债表</a>
    <a href="#/financialStatements?profit" class="easyui-linkbutton l-btn l-btn-large" style="width:200px;height:45px;display:inline-block;">利润表</a>
    <a href="#/financialStatements?money" class="easyui-linkbutton l-btn l-btn-large" style="width:200px;height:45px;display:inline-block;">现金流量表</a>
 </div>

页面二在加载前进行判断:

    mounted:function(){
            //url#后面的分段
            var str = window.location.hash;
            var list = str.split("#/financialStatements?");
            if(list.indexOf("byYear")==1){
                $("#twoYear").hide();
                $("#threeYear").hide();
                $("#debet").hide();
                $("#profit").hide();
                $("#money").hide();
            }else if(list.indexOf("debet")==1){
                $("#byYear").hide();
                $("#profit").hide();
                $("#money").hide();
            }else if(list.indexOf("profit")==1){
                $("#byYear").hide();
                $("#debet").hide();
                $("#money").hide();
            }else if(list.indexOf("money")==1){
                $("#byYear").hide();
                $("#debet").hide();
                $("#profit").hide();
            }       
    }

window.location.hash;//这个会获得href中#后面的字段,然后可以通过参数的不同,进行div的隐藏和显示,
这里使用的jquery的$("#twoYear").hide();和$("#threeYear").show();
这里使用的是vue的mounted,需要先加载页面再进行function;
mounted:在模板渲染成html后调用,通常是初始化页面完成后,再对html的dom节点进行一些需要的操作.
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
好的,下面是三个功能的示例代码: 1. 创建根据不同来宾显示不同内容的欢迎栏: HTML代码: ```html <div id="welcome-bar"></div> ``` JavaScript代码: ```javascript // 获取当前用户信息 // 这里假设已经有一个函数getUserInfo()可以获取当前用户信息 const userInfo = getUserInfo(); // 根据用户信息生成欢迎栏内容 let welcomeMsg; if (userInfo && userInfo.isLoggedIn && userInfo.role === 'admin') { welcomeMsg = `欢迎,管理员${userInfo.name}!<a href="/admin">进入管理后台</a>`; } else if (userInfo && userInfo.isLoggedIn) { welcomeMsg = `欢迎,${userInfo.name}!`; } else { welcomeMsg = '欢迎访问我们的网站!<a href="/login">登录</a> 或 <a href="/register">注册</a>'; } // 将欢迎栏内容添加到页面 const welcomeBar = document.getElementById('welcome-bar'); welcomeBar.innerHTML = welcomeMsg; ``` 2. 退出页面显示浏览当前页面的时间: JavaScript代码: ```javascript // 获取页面加载时的时间戳 const startTime = Date.now(); // 在窗口卸载时计算停留时间并显示提示信息 window.addEventListener('beforeunload', () => { const stayTime = Math.round((Date.now() - startTime) / 1000); // 停留时间,单位:秒 alert(`您在本页面停留了${stayTime}秒。`); }); ``` 3. 实现复制表单: HTML代码: ```html <form id="my-form"> <!-- 表单内容 --> </form> <button id="copy-btn">复制表单内容</button> ``` JavaScript代码: ```javascript // 获取要复制的表单内容 const form = document.getElementById('my-form'); const formContent = form.innerHTML; // 在按钮点击时将表单内容复制到剪贴板 const copyBtn = document.getElementById('copy-btn'); copyBtn.addEventListener('click', () => { navigator.clipboard.writeText(formContent).then(() => { alert('表单内容已复制到剪贴板。'); }); }); ``` 希望这些代码能够帮助到你,如果你有任何疑问或需要进一步的帮助,请随时提出。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值