小编Dr *_*r I的帖子

addEventListener类型'click'实际上就像'load'

大家,早安,

我目前正在尝试在网页上添加一点动态,所以我决定使用事件监听器加载外部页面而不重新加载所有页面.

从这一点开始,我做了以下测试页面内容:

HTML:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Test</title>
<link href="http://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet" type="text/css">
<link type="text/css" rel="stylesheet" media="all" href="./assets/css/style.css">
</head>
<body>
    <header>
        <nav>
            <ul>
                <li><h1>Tagline of the page</h1></li>
                <li id="login"><h1><a href="#" id="authentication">Classic Authentication</a></h1></li>
            </ul>
        </nav>
    </header>
    <section id='messages'>
        <p class="title">I'm sorry dave, but you can't access this facility right now!</p>
    </section>
    <script src="/assets/scripts/ajax.js"></script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

使用Javascript:

function loadview(url, id) {
    var xhr_object = null; 

    if (window.XMLHttpRequest) { 

        xhr_object = new XMLHttpRequest();

        xhr_object.open("GET", url, true);

        xhr_object.onreadystatechange = function(){

            if (xhr_object.readyState …
Run Code Online (Sandbox Code Playgroud)

javascript javascript-events

0
推荐指数
1
解决办法
593
查看次数

标签 统计

javascript ×1

javascript-events ×1