繁体   English   中英

如何使用javascript加载我页面上的所有元素?

[英]how to load all elements on my page with javascript?

我有一个动态页面,每个页面都有不同的元素,我想将它们的所有行加载到例如警报或带有 JavaScript 的页面。 这可能吗?

例如,如果我的页面上有这一行:

<marquee> This is for test </marquee>

我想将所有内容显示在警报或页面上,例如:

伪代码:

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

输出:(在警报中)

<marquee> 这是为了测试 </marquee>

您可以使用Ajax 这是一个alert页面test.aspx内容的示例,例如:

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);

如需更多信息,请谷歌“Ajax”。 有很多很好的教程。

暂无
暂无

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

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