简体   繁体   中英

how to load all elements on my page with javascript?

I have a dynamic page with different elements in each generates, and I want to load all of their lines to an alert for example or a page with JavaScript. Is this possible?

For example, if I had this line to my page:

<marquee> This is for test </marquee>

I want to show all of it to an alert or a page, somethings like that :

Pseudo-code:

<script>
alert(getAllData) | write(getAllData)
</script>

Output: (in alert)

<marquee> This is for test </marquee>

You can use Ajax . Here's an example that alert s the contents of the page test.aspx , for example:

var rq;

// Initialize the request:
if(window.XMLHttpRequest) {
    rq = new XMLHttpRequest(); // Standards-compliant way, compatible with every browser except IE6 and under
} else {
    rq = new ActiveXObject('Msxml2.XMLHTTP'); // IE6-compatible.
}

// Open the request:
rq.open('GET', 'test.aspx', true); // GET is the method (you're probably familiar with this), test.aspx is the URL, and true means send asynchronously.

// Set up the state-change handler:
rq.onreadystatechange = function() {
    if(rq.readyState === 4) { // Request complete
        alert(rq.responseText); // The response is in the responseText property.
    }
};

// Finally, send the request:
rq.send(null);

For more information, Google "Ajax." There are plenty of good tutorials.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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