[英]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.我有一个动态页面,每个页面都有不同的元素,我想将它们的所有行加载到例如警报或带有 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>
<marquee> 这是为了测试 </marquee>
You can use Ajax .您可以使用Ajax 。 Here's an example that
alert
s the contents of the page test.aspx
, for example:这是一个
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);
For more information, Google "Ajax."如需更多信息,请谷歌“Ajax”。 There are plenty of good tutorials.
有很多很好的教程。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.