In the webpage, the button does not have the attribute of tag a. If we want to add a jump event to the button, we can click the jump js on The onclick event, below I will introduce some common methods.
How can I jump to another page by clicking the button? We may need this in website production, because sometimes we need this effect, especially when we make a button into an image and click an image to jump to a new page, how can this problem be achieved?
This effect can be achieved through onclick = "window. location = 'new page.
1. directly jump to the original form using
| The Code is as follows: |
Copy code |
|
Window. location. href = "the page you want to jump "; |
2. Open the page in the new form:
| The Code is as follows: |
Copy code |
|
Window. open ('page you want to jump ');
Window. history. back (-1); return to the previous page |
The code is:
| The Code is as follows: |
Copy code |
|
<Input type = "submit" name = "Submit" value = "agree" onclick = window. open (http://www.bKjia. c0m/)> |
If you want to verify that the input amount is filled in when you click the button to submit, what should you do? When the user name is entered or other fields are empty, click the button to do not submit. You can follow the methods below.
| The Code is as follows: |
Copy code |
|
<Input type = "submit" name = "submit" onclick = "open ()">
<Script language = javascript>
Fuction open (){
If (! Document. form_name.username.value ){
Alert ("Enter the user name! "); Document. form_name.username.focus (); return false;
} Else document. form_name.action = "aaa.htm ";
}
</Script> |
In this case, when the value is null, the button will not jump to another page? In this way, the effect is achieved.
JS jump page reference code
| The Code is as follows: |
Copy code |
|
First:
<Script language = "javascript" type = "text/javascript">
Window. location. href = "login. jsp? Backurl = "+ window. location. href;
</Script>
Second:
<Script language = "javascript">
Alert ("return ");
Window. history. back (-1 );
</Script>
Third:
<Script language = "javascript">
Window. navigate ("top. jsp ");
</Script>
Fourth:
<Script language = "JavaScript">
Self.location+'top.htm ';
</Script>
Category 5:
<Script language = "javascript">
Alert ("illegal access! ");
Top. location = 'xx. jsp ';
</Script>
===== Jump to other pages through the pop-up selection box in javascript ====
<Script language = "javascript">
<! --
Function logout ()...{
If (confirm ("are you sure you want to log out of your identity? Yes-Select OK, no-select cancel "))...{
Window. location. href = "logout. asp? Act = logout"
}
}
-->
</Script>
===== Jump to other pages through a prompt box in javascript ====
<Script language = "javascript">
<! --
Function logout ()...{
Alert ("are you sure you want to cancel your identity? ");
Window. location. href = "logout. asp? Act = logout"
}
-->
</Script> |