Home Web Front-end HTML Tutorial Introduction to the method of adding a submit link to a button in an HTML static page

Introduction to the method of adding a submit link to a button in an HTML static page

Jul 27, 2017 pm 02:15 PM
button html

1. The button looks like a link (picture)
Submit button

<input type="submit" value="提交">
Copy after login

Submit link

<a href="#" onclick="表单名字.submit()">提交</a>
Copy after login

Reset button

<input type="reset" value="重置">
Copy after login

Reset link

<a href="#" onclick="表单名字.reset()">重置</a>
Copy after login

Normal button

<input type="button" value="按钮" onclick="函数()">
Copy after login

Normal link

<a href="#" onclick="函数()">链接</a>
Copy after login

As for the picture, do the same and replace the a tag with img
2. Make the link look like a button

<a href="reg.asp">注册</a>
=><input type="button" value="注册" onclick="location.href=&#39;reg.asp&#39;">
Copy after login

----------------------------------
Sometimes we can do it by hand A form with get mode, you can use buttons or links as you like.

<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="提交">
</form>
=>
<input name="aa" type="text" id="aa">
<input name="bb" type="text" id="bb">
<input type="button" value="按钮" onclick="location.href=&#39;xx.asp?aa=&#39;+document.all[&#39;aa&#39;].value+&#39;&bb=&#39;+document.all[&#39;bb&#39;].value">
Copy after login

----------------------------------
further We can also make a button (link) to simultaneously transfer 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
假设有rs("id4")=4
...
%>
<input name="id2" type="text" id="id2" value="2">
<input type="button" value="按钮"
onclick="location.href=&#39;xx.asp?id1=&#39;+id1+&#39;&id2=&#39;+document.all[&#39;id2&#39;].value+&#39;&id3=<%=id3%>&id4=<%=rs("id4")%>&#39;">
Copy after login

When we press the button, we will see that the browser's 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 this a disguised variable transfer between the client js and the server segment?
-------------------------------------------------- -------------------------------------------------- --------------------------
How to add link function to button

Solution:
The button is a control-level object with a relatively high priority, so it cannot be directly linked like a picture or text. It can only be implemented by calling a script through the click event of the button.
Specific steps:
1. Open the link in the original window

    <input type="button" 
value="闪吧" onClick="location=’http://www.xxx.net’">
    <button onClick="location.href=’http://www.xxxx.net’">闪吧</button>
    <form action="http://www.xxxx.net%22%3e%3cinput/ type="submit" value="打开链接"></form>
Copy after login

2. Open the link in a new window

<input type="button" 
value="闪吧" onClick="window.open(’http://www.xxxx.net’)">
    <button onClick="window.open(’http://www.xxxx.net’)">ggg</button>
    <form action="http://www.xxxx.net/" 
target="_blank"><input type="submit" value="打开链接"></form>
Copy after login


Note: onClick call The quotation marks in the code can be nested single or double when there is only one quotation mark. If there are more than two quotation marks, they must be escaped with "\" and the escaped quotation marks must be consistent with the inner quotation marks, such as:

<button onClick="this.innerHTML=’<font color=\’red\’>http://www.xxxx.net</font>’">闪吧</button>
Copy after login

or

<button onClick=’this.innerHTML="<font color=\"red\">http://www.xxxx.net</font>"’>闪吧</button>
Copy after login

and the following are wrong ways of writing:

<button onClick="this.innerHTML=’<font color=’red’>http://www.xxxx.net</font>’">闪吧</button>
<button onClick="this.innerHTML=’<font color="red">http://www.xxxx.net</font>’">闪吧</button>
<button onClick="this.innerHTML=’<font color=\"red\">http://www.xxxx.net</font>’">闪吧</button>
Copy after login

Tip: Most methods and properties belonging to window or document objects can omit the prefix window or document, for example, location.href in this example (location.href can also be abbreviated as location, because the default object of location is href) is the elliptical way of writing window.location.href or document.location.href.

Tips: In this example, you can also use the following method to replace location.href

location.replace(url)
location.assign(url)
navigate(url)
Copy after login

Special Tips

After the code in the first step is run, click Clicking the button will jump to the link target. The second step will open the link in a new window after clicking the button.

Special Note

This example mainly uses onClick to capture the user's click event on the button, and then calls the href method of the location object or the open method of the window object to open the link. Another trick is to implement the link function by submitting a form. The button must be of type=submit type. The action value of the form is the link target, and the target value is the target method of opening the link.

The above is the detailed content of Introduction to the method of adding a submit link to a button in an HTML static page. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Table Border in HTML Table Border in HTML Sep 04, 2024 pm 04:49 PM

Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

Nested Table in HTML Nested Table in HTML Sep 04, 2024 pm 04:49 PM

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

HTML margin-left HTML margin-left Sep 04, 2024 pm 04:48 PM

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

HTML Table Layout HTML Table Layout Sep 04, 2024 pm 04:54 PM

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

HTML Input Placeholder HTML Input Placeholder Sep 04, 2024 pm 04:54 PM

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

HTML Ordered List HTML Ordered List Sep 04, 2024 pm 04:43 PM

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

Moving Text in HTML Moving Text in HTML Sep 04, 2024 pm 04:45 PM

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.

HTML onclick Button HTML onclick Button Sep 04, 2024 pm 04:49 PM

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.

See all articles