前端data-url的用法
阿新 • • 發佈:2018-12-17
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>