jquery触发a标签跳转事件示例代码

2020-05-19 07:28:36易采站长站整理

1.写入<a>标签:
<a target=”_blank” href=”javascript:void(0)” onclick=”checkValidate()”>水觅微博</a>
2.加入JS:

<script type=”text/javascript”>
function checkValidate(){
if($(“#signOut”).text()){
window.location.href=”<%=basePath%>/jsp/weibo/index.jsp”;
}else{
window.location.href=”<%=basePath%>index.jsp”;
}
}
</script>

3.解释:
$(“#signOut”).text()为我所需要判断的对应ID的Html元素的值