


javascript setTimeout() passes function parameters (including passing object parameters)_javascript skills
So, I searched online and used another writing method setTimeout("fun(" parameter ")", 1000), but it still didn't work. However, the above writing method is OK when passing the textarea of the form form. For example, hml is like this:
In js I can write like this:
setTimeout("doAjax(document. sform.txtara.value )", 1000);
But once you want to pass other parameters or object parameters, you have to rewrite this function according to the methods provided on the Internet.
After research and practice, I have improved the method myself. You can refer to it. I only base it on my personal needs. I cannot guarantee other situations. Please give me your advice!
JavaScript:
function initAjax() {
var httprequest=null;
try {
httprequest =new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
httprequest=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {
try {
httprequest=new XMLHttpRequest();
}
catch (e) {
httprequest=null;
}
}
}
return httprequest;
}
function doAjax( msg, obj ) {
var obj=obj; // Mainly this line
alert( obj.value);
var he="he=" msg;
var ajaxrequest=initAjax();
ajaxrequest.open("POST", "abc.jsp", true);
ajaxrequest.setRequestHeader( "Content-Type" , "application/x-www-form-urlencoded;charset=utf-8");
ajaxrequest.send(he);
ajaxrequest.onreadystatechange=function() {
if (ajaxrequest.readyState= =4) {
if (ajaxrequest.status==200) {
document.getElementById("showpane").innerHTML=ajaxrequest.responseText;
}
else {
doAjax( msg );
}
}
}
setTimeout("doAjax(document.sform.txtara.value,document.all[" obj.sourceIndex "])", 100);//Also This line
}
In this way, I solved the problem of object parameter passing. Finally, I would like to say that if you have a better solution, please leave a comment. I am happy to cooperate with like-minded people. study!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

WebSocket and JavaScript: Key technologies for realizing real-time monitoring systems Introduction: With the rapid development of Internet technology, real-time monitoring systems have been widely used in various fields. One of the key technologies to achieve real-time monitoring is the combination of WebSocket and JavaScript. This article will introduce the application of WebSocket and JavaScript in real-time monitoring systems, give code examples, and explain their implementation principles in detail. 1. WebSocket technology

Function parameter passing methods and thread safety: Value passing: Create a copy of the parameter without affecting the original value, which is usually thread safe. Pass by reference: Passing the address, allowing modification of the original value, usually not thread-safe. Pointer passing: Passing a pointer to an address is similar to passing by reference and is usually not thread-safe. In multi-threaded programs, reference and pointer passing should be used with caution, and measures should be taken to prevent data races.

C++ indefinite parameter passing: implemented through the... operator, which accepts any number of additional parameters. The advantages include flexibility, scalability, and simplified code. The disadvantages include performance overhead, debugging difficulties, and type safety. Common practical examples include printf() and std::cout, which use va_list to handle a variable number of parameters.

JavaScript and WebSocket: Building an efficient real-time weather forecast system Introduction: Today, the accuracy of weather forecasts is of great significance to daily life and decision-making. As technology develops, we can provide more accurate and reliable weather forecasts by obtaining weather data in real time. In this article, we will learn how to use JavaScript and WebSocket technology to build an efficient real-time weather forecast system. This article will demonstrate the implementation process through specific code examples. We

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

Introduction to the method of obtaining HTTP status code in JavaScript: In front-end development, we often need to deal with the interaction with the back-end interface, and HTTP status code is a very important part of it. Understanding and obtaining HTTP status codes helps us better handle the data returned by the interface. This article will introduce how to use JavaScript to obtain HTTP status codes and provide specific code examples. 1. What is HTTP status code? HTTP status code means that when the browser initiates a request to the server, the service

There are two ways to pass function parameters in C++: call by value (which does not affect the actual parameters) and call by reference (which affects the actual parameters). Passing out parameters is achieved by passing a reference or pointer, and the function can pass the value to the caller by modifying the variable pointed to by the parameter reference or pointer. Please note when using: The outgoing parameters must be clearly declared, can only correspond to one actual parameter, and cannot point to local variables within the function. When calling by passing a pointer, be careful to avoid wild pointers.

Yes, in many programming languages, arrays can be used as function parameters, and the function will perform operations on the data stored in it. For example, the printArray function in C++ can print the elements in an array, while the printArray function in Python can traverse the array and print its elements. Modifications made to the array by these functions are also reflected in the original array in the calling function.
