How to add a link to a button

Source: Internet
Author: User
Tags id3

Script description:
Add the following code to the <body> area:
<Input type = "Submit" value = "" onclick = "location. href = 'HTTP: // www.jzzy.com '">

Click to move the button
As a tip, it is temporarily classified into ASP.
When designing a website, we may want to make the link look like a button, and the button looks like a link. The following describes my methods.
1. Make the button look like a link (image)
Submit button <input type = "Submit" value = "Submit">
Submit link <a href = "#" onclick = "form name. Submit ()"> submit </a>
Reset button <input type = "reset" value = "reset">
Reset link <a href = "#" onclick = "form name. Reset ()"> Reset </a>
Normal button <input type = "button" value = "button" onclick = "function ()">
Normal link <a href = "#" onclick = "function ()"> link </a>
As for the image, the label is also changed to IMG.
2. Make the link look like a button
<A href = "Reg. asp"> Registration </a>
=> <Input type = "button" value = "register" onclick = "location. href = 'reg. asp '">
-----------------------------------
Sometimes we can create a get form manually, and use buttons or links as needed.
<Form action = "XX. asp" method = "get" name = "form1">
<Input name = "AA" type = "text" id = "AA">
<Input name = "BB" type = "text" id = "BB">
<Input type = "Submit" name = "Submit" value = "Submit">
</Form>
=>
<Input name = "AA" type = "text" id = "AA">
<Input name = "BB" type = "text" id = "BB">
<Input type = "button" value = "button" onclick = "location. href = 'xx. asp? AA = '+ document. All ['a']. Value +' & BB = '+ document. All ['bb']. Value ">
-----------------------------------
Further, we can also make a button (Link) to simultaneously pass JS variables, form input values, ASP variables, and recordset values.
<Script language = "JavaScript">
VaR id1 = 1;
</SCRIPT>
<%
ID3 = 3
....
Rs. Open exec, Conn, 1, 1
Assume that RS ("ID4") = 4
...
%>
<Input name = "ID2" type = "text" id = "ID2" value = "2">
<Input type = "button" value = "button"
Onclick = "location. href = 'xx. asp? Id1 = '+ id1 +' & Id2 = '+ document. all ['id2']. value + '& ID3 = <% = ID3 %> & ID4 = <% = RS ("ID4") %>' ">
When we press the button, the browser URL is XX. asp? Id1 = 1 & Id2 = 2 & ID3 = 3 & ID4 = 4
In XX. asp, we can use request. querystring to get all the variables. Is it possible to transfer the variables of client JS and server segments in disguise?
Bytes ------------------------------------------------------------------------------------------------------------------------------
How to add a link to a button

Solution:
The button is a control-level object with a high priority. Therefore, you cannot directly add links like images or text. You can only use the button-clicking event to call scripts.
Procedure:
1. Open the link in the original window
<Input type = "button" value = "" onclick = "location = 'HTTP: // www.flash8.net '">
<Button onclick = "location. href = 'HTTP: // www.flash8.net '"> flash </button>
<Form action = "http://www.flash8.net"> <input type = "Submit" value = "open link"> </form>
2. Open the link in a new window
<Input type = "button"
Value = "Flash" onclick = "window. Open ('HTTP: // www.flash8.net ')">
<Button onclick = "window. Open ('HTTP: // www.flash8.net ')"> flash </button>
<Form action = "http://www.flash8.net"
Target = "_ blank"> <input type = "Submit" value = "open link"> </form>
Note: The quotation marks in the onclick call code can be nested in a single pair when there is only one weight. If there are more than two duplicates, you must use the "/" escape and the escaped quotation marks must be consistent with the quotation marks in the lower layer, for example:
<Button onclick = "This. innerhtml = '<font color =/'Red/'> http://www.flash8.net </font> '"> flash </button>
Or
<Button onclick = 'this. innerhtml = "<font color =/" Red/"> http://www.flash8.net </font>" '> flash </button>
The following are incorrect statements:
<Button onclick = "This. innerhtml = '<font color = 'red'> http://www.flash8.net </font>'"> flash </button>
<Button onclick = "This. innerhtml = '<font color =" red "> http://www.flash8.net </font>'"> flash </button>
<Button onclick = "This. innerhtml = '<font color =/" Red/"> http://www.flash8.net </font>'"> flash </button>
Tip: Most methods and attributes that belong to the window or document object can omit the prefix window or document, for example, location in this example. href (location. href can also be abbreviated as location, because the default object of location is href) is window. location. href or document. location. the omitted href format.
Tip: In this example, you can use the following method to replace location. href.
Location. Replace (URL)
Location. Assign (URL)
Navigate (URL)
Note
After the code in step 1 is run, click the button to jump to the Link Target. The second step opens the link in the new window after clicking the button.
Note

In this example, you can use onclick to capture click events of a user on a button, and then call the location object's href method or window object's open method to open the link. Another trick is to implement the link function by submitting a form. The button must be of the type = submit type. The action value of the form is the link target, and the target value is the Link Opening target.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.