简体   繁体   English

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

[英]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.

相关问题 如何使某个javascript函数在页面加载时对其所有元素执行? - How do I make a certain javascript function execute on page load for all its elements? Javascript:在页面加载时按类名获取所有元素不起作用 - Javascript: get all elements by class name on page load NOT WORKING 如何使用 Jquery/Javascript 将我的一个文件夹中的所有图像加载到我的网页中 - How to load all the images from one of my folder into my web page, using Jquery/Javascript 如何更改页面中所有元素的CSS-JavaScript - How to change the CSS of all the elements in the page - JavaScript 如何使用javascript为页面中的所有元素添加事件监听器,这些元素的ID在我的数组中 - How to add Eventlistener for all Elements in the page which thier ids are inside my Array using javascript 使用Javascript触发器加载所有元素 - Javascript trigger for load of all elements 如何使用jQuery / JavaScript将子文件夹中的所有文件名加载到我的安全网页中 - How to load all the file names from a sub folder into my secure web page, using jQuery/JavaScript 如何在加载其他页面元素后加载 javascript? - How to make a javascript load after other page elements are loaded? Javascript:如何遍历页面上的所有 DOM 元素? - Javascript: How to loop through ALL DOM elements on a page? 如何使JavaScript函数在页面的所有元素上运行 - How to make a JavaScript function run on all elements of the page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM