前端data-url的用法

data-* 相当于数据存储,点加了点击方法,就会读取里面的数据,进行页面跳转

<div class="level02_guide">

                    <ul class="title">
                        <li><span<#if type=='companyNotice'>
                                class="l02_active" </#if>
                                data-url="${webHomeUrl}/article/companyNotice/index"
                                data-type="/article/companyNotice/index">公司公告</span></li>
                        <li><span<#if type=='news'> class="l02_active" </#if>
                                data-url="${webHomeUrl}/article/news/index"
                                data-type="/article/news/index">业界新闻</span></li>
                    </ul>
                    <script type="text/javascript">
                        $(function() {
                            $('.level02_guide>ul>li>span')
                                    .on(
                                            'click',
                                            function() {
                                                var newsurl = $(this).attr(
                                                        "data-url");
                                                var newType = $(this).attr(
                                                        "data-type");
                                                var oldUrl = location.href;
                                                if (oldUrl.toLowerCase()
                                                        .indexOf(newType) < 0) {
                                                    location.href = newsurl;
                                                }
                                            });
                        });

                    </script>

<div>

猜你喜欢

转载自blog.csdn.net/wudiansheng/article/details/80079006