点击跳转页面并执行跳转页面中的某个函数

1、新建html文件

<!DOCTYPE html>
<html lang="en">
head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.js"></script>
    <title>Document</title>
</head>
<body>
    <a href="test.html" id="type">Type</a>
    <script type="text/javascript">
        $('#type').on('click', function() {
            sessionStorage.setItem("type", "type");
        });
    </script>
</body>
</html>

2、新建html文件(跳转页面)

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.js"></script>
    <title>Document</title>
</head>
<body>
    <a class="type" onclick="type1()">商业物业</a>
    <script type="text/javascript">
        function type1() {
            alert("出现了");
        }
    </script>
    <script type="text/javascript">
        window.onload = function() { //页面加载完成后再执行
            var type = sessionStorage.getItem("type");
            console.log(type); //打印type值
            if (type == 'type') {
                var obj = "." + type;
                obj.onclick = type1(); //要触发的点击事件  $('#xxx').click()
                sessionStorage.setItem("type", ""); //清除 type 防止在test页面刷新后依然触发$('#xxx').click()
            }
        }
    </script>
</body>
</html>

3、开心的执行了!
4、还有一种是类似get方式传参,但是我觉得太麻烦了,具体取值可以参考我的另一篇文章http://www.jianshu.com/p/3a449542a4d6,反正思路就是这样

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值