简体   繁体   English

javascript或jquery来更改div的innerHTML?

[英]javascript or jquery to change innerHTML of a div?

This function allow me to load a webform/popup above my page test.aspx 此功能允许我在页面test.aspx上方加载Webform /弹出窗口

  $(document).ready(function () {
  $('#<%= webform.ClientID %>').load('pop_up_one.html');})

I now would like to change the innerhtml of this popup with another popup and have the possibility to come back to the first popup. 我现在想用另一个弹出窗口更改此弹出窗口的innerhtml,并有可能回到第一个弹出窗口。 Basicly I just want to change the innerhtml of the DIV of the first pop_up 基本上我只想更改第一个pop_up DIV的innerhtml

How is possible to do that? 如何做到这一点? thought adding something like: 想添加类似的东西:

   $('#div_of_popup_one').click.load('pop_up_two.html');

but this does not work. 但这不起作用。

The only way I found to make it work has been to integrate this code into pop_up_1-html: 我发现使其生效的唯一方法是将以下代码集成到pop_up_1-html中:

    function loadextPage(event) {
        var xmlhttp = new XMLHttpRequest();
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                document.getElementById('name_of_div_to_change').innerHTML = xmlhttp.responseText;
            }
        }
        xmlhttp.open("GET", event.target.href, true);
        xmlhttp.send();
    }

and call this from: 并从以下调用:

Go to second pop up 转到第二个弹出窗口

This method works but i would like to do it with something like 这种方法有效,但我想用类似的方法

        $('#div_of_popup_one').click.load('pop_up_two.html')

from the page i am calling the pop_up_one 从页面中,我正在调用pop_up_one

To do this, first you need to, bind click event and then invoke click . 为此,首先需要绑定click事件,然后调用click Use the following code. 使用以下代码。

   $('#div_of_popup_one').on("click", function() {
       $(this).load('pop_up_two.html');
   });

   $('#div_of_popup_one').click();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM