Html 一个页面中的不同页面及其事件

Html 一个页面中的不同页面及其事件,html,Html,我正在另一个页面中显示一个html页面。我没有使用框架。相反,我利用了javascript并在一个页面中显示不同的页面。在这里,我给出了如何在另一个网页中显示该网页的示例代码 <html> <head> <title>Test</title> <style> #headerDiv{ top: 0; width: 100%

我正在另一个页面中显示一个html页面。我没有使用框架。相反,我利用了javascript并在一个页面中显示不同的页面。在这里,我给出了如何在另一个网页中显示该网页的示例代码

<html>
<head>
    <title>Test</title>     
    <style>
        #headerDiv{         
            top: 0;
            width: 100%
            display: block;
            //border-bottom: 3px solid #808080;
        }
        #headerHR{                                              
            width: 100%;
            height: 1px;
        }
        #headerImg{
            float: left;
            margin-top: 0px;
            margin-left: 0px;
        }
        #headerPre{
            float: left;
            font-family: "Arial", Helvetica, sans-serif;
            font-style: normal;
            font-weight: bold;
            font-size: 24px;
        }
        #navDiv{
            position: absolute;             
        }
        #gapFillerDiv{
            overflow: hidden;
        }
    </style>
    <script type="text/javascript" src="./jquery/jquery-1.12.4.min.js"></script>        
    <script type="text/javascript">
        $(document).ready(function(){               
                    $('#sensors').load('./nav.html');
           });
    </script>
    <script type="text/javascript">

    </script>
</head> 
<body>
    <div id="headerDiv">
        <img id="headerImg" src="./assets/dummyLogo.png" width="280" height="125" alt="DummyLogo"/>
        <pre id="headerPre">
                 Test Series
        Test Solutions
        </pre>                  
        <hr id="headerHR">
    </div>      
    <p id="test"></p>
    <div id="sensors"  style="position: fixed; top: 138px;"></div>      
</body>

试验
#校长{
排名:0;
宽度:100%
显示:块;
//边框底部:3px实心#808080;
}
#校长{
宽度:100%;
高度:1px;
}
#人头肌{
浮动:左;
边际上限:0px;
左边距:0px;
}
#校长{
浮动:左;
字体系列:“Arial”,Helvetica,无衬线;
字体风格:普通;
字体大小:粗体;
字体大小:24px;
}
#导航师{
位置:绝对位置;
}
#加普菲列尔迪夫{
溢出:隐藏;
}
$(文档).ready(函数(){
$(“#传感器”).load(“./nav.html”);
});
测试系列
试验溶液


在上面的代码中,我在一个名为test.html的页面中显示了一个网页nav.html。在nav.html中有一个简单的按钮。我想在test.html页面中查看test.html页面中显示的nav.html页面的按钮单击结果。我该怎么做

您可以像其他处理程序一样使用按钮单击处理程序

由于按钮是在DOM加载后添加到页面中的,因此最简单的方法是使用jQuery的
.on()
和附加选择器。大概是这样的:

$(document).on('click', '#yourButton', function () {
    // your handler
});
$('#sensors').on('click','button',function(){
   alert('button click in #sensors wrapper');
});
只需将
#您的按钮
替换为识别按钮的选择器即可。其工作方式是,单击处理程序实际上附加到
文档
,并且可以对文档中的任何位置进行任何单击调用,但是作为
参数的第二个选择器。on()
是一个过滤器,在调用事件时应用于单击事件发起人,以便它仅应用于目标元素


关于这一点,我已经写了一些更深入的内容,我相信其他许多人也有。

您可以像其他任何人一样使用按钮单击处理程序

由于按钮是在DOM加载后添加到页面中的,因此最简单的方法是使用jQuery的
.on()
和附加选择器。大概是这样的:

$(document).on('click', '#yourButton', function () {
    // your handler
});
$('#sensors').on('click','button',function(){
   alert('button click in #sensors wrapper');
});
只需将
#您的按钮
替换为识别按钮的选择器即可。其工作方式是,单击处理程序实际上附加到
文档
,并且可以对文档中的任何位置进行任何单击调用,但是作为
参数的第二个选择器。on()
是一个过滤器,在调用事件时应用于单击事件发起人,以便它仅应用于目标元素


关于这一点,我已经写了一些更深入的东西,我相信许多其他人也写过。

你可以这样做:

$(document).on('click', '#yourButton', function () {
    // your handler
});
$('#sensors').on('click','button',function(){
   alert('button click in #sensors wrapper');
});

你可以这样做:

$(document).on('click', '#yourButton', function () {
    // your handler
});
$('#sensors').on('click','button',function(){
   alert('button click in #sensors wrapper');
});

谢谢你的回复。这真的很有帮助。谢谢你的回复。这真的很有帮助。