| |

VerySource

 Forgot password?
 Register
Search
View: 816|Reply: 7

How to write this js?

[Copy link]

2

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-2-9 16:00:02
| Show all posts |Read mode
I need such a variable in a js function. This variable is automatically incremented by 1 each time this function is called.
Reply

Use magic Report

0

Threads

64

Posts

45.00

Credits

Newbie

Rank: 1

Credits
45.00

 China

Post time: 2020-4-3 11:15:01
| Show all posts
var i;
function add ()
{
i = i + 1;
}
Reply

Use magic Report

2

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-4-4 08:15:01
| Show all posts
Help me see why this is wrong?
 <img border = "0" height = "29" onload = "javascript: Getid (this)" src = "../ images / plus.gif" width = "20" />
-----------------------
var countid;
function Getid (obj)
{
    countid = countid + 1;
    obj.id = "img" + countid;
    var a = obj.id;
}
-----------------------
This function will be called four times when the page is onload, but the four times I am all img1
Reply

Use magic Report

0

Threads

64

Posts

45.00

Credits

Newbie

Rank: 1

Credits
45.00

 China

Post time: 2020-4-4 12:15:01
| Show all posts
If the page refreshes, it is the initial value every time
Reply

Use magic Report

0

Threads

29

Posts

23.00

Credits

Newbie

Rank: 1

Credits
23.00

 China

Post time: 2020-4-4 15:00:02
| Show all posts
var dd = "obj.id = img" + countid;
eval (dd);
    var a = obj.id;
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-4-4 17:15:02
| Show all posts
<script language = "javascript" type = "text / javascript">
     function validate ()
                        {
                            if (document.getElementById ("<% = username.ClientID%>"). value == "")
                            {
                                        alert ("User name cannot be empty!");
                                        document.getElementById ("<% = username.ClientID%>"). focus ();
                                        return false;
                            }
                            
                            if (document.getElementById ("<% = txtpassword.ClientID%>"). value == "")
                            {
                                        alert ("Password cannot be empty!");
                                        document.getElementById ("<% = txtpassword.ClientID%>"). focus ();
                                        return false;
                            }
                            
                            var biaodashi = ". * [=} ']. *";
                            var username = document.getElementById ("<% = username.ClientID%>"). value;
                            var psword = document.getElementById ("<% = txtpassword.ClientID%>"). value;
                            var matchArray = username.match (biaodashi);
                            var matchArraypw = psword.match (biaodashi);
                            if (matchArray! = null || matchArraypw! = null)
                            {
                                    alert ("Illegal character input has recorded your IP address!");
                                    document.getElementById ("<% = username.ClientID%>"). focus ();
                                    return false;
                            }
                            }
    </ script>

just for reference
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-4-4 17:30:02
| Show all posts
<html>

<head>
<script language = javascript>

var obj =
{
i: 0, // value of variable
add: function () // Function call, increase variable value by 1
{
this.i = this.i + 1;
alert ("the value of i is:" + this.i);
}
The
}
</ script>
</ head>
<body>
<input type = button onclick = "obj.add ();" value = "Add 1 to variable i and display">
</ body>
</ html>
Reply

Use magic Report

3

Threads

14

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-4-5 09:15:02
| Show all posts
Can be achieved with setTimeout, but will always display these pictures`
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list