html的a标签如何实现2个事件

html-css08

html的a标签如何实现2个事件,第1张

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <title>Title</title>

</head>

<body>

<a href="javascript:href()" target="_blank">跳转</a>

<script>

    function href() {

        if (localStorage.length == 0)

        {

            localStorage.setItem("count",true)

            location.href = "https://www.baidu.com"

 }else {

            location.href = "https://www.bilibili.com"

 localStorage.clear()

        }

    }

</script>

</body>

</html>

代码如上,第一次跳转到百度,第二次跳转到哔哩哔哩

如果只是单纯的点击跳转的话,直接加跳转的目标地址即可;如:

<a href="http://www.baidu.com">百度</a>

如果是要写其点击事件函数的话,直接用click()函数,如:

JQ代码:

$("a").click(function(){

    //要执行的代码写在这里

})

从后台代码页加的话是加在LinkButton上,

LinkButton.Attributes["onclick"] = "xxx"

onclick是客户端事件,只能引起客户端事件。