Home > Web Front-end > JS Tutorial > Use JS to manipulate input text box content

Use JS to manipulate input text box content

php中世界最好的语言
Release: 2018-05-02 09:48:11
Original
5996 people have browsed it

This time I will bring you the use of JS to operate the content of the input text box. What are the precautions for using JS to operate the content of the input text box? The following is a practical case, let's take a look.

1 Introduction

Getting the text box and modifying its content can be achieved using the

getElementById() method.

getElementById()The method can get the HTML tag by the specified id and return it.

Syntax:

##sElement=

document.getElementById(id)<a href="//m.sbmmt.com/code/658.html" target="_blank"></a>

sElement

: Used to receive a object returned by this method.

id

: Used to set the id value that needs to be obtained from the HTML tag.

Second ApplicationGet the text box and modify its content

It will be displayed in the text box after the page is loaded "Initial text content", the content in the text box will be changed when the button is clicked.

三码

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>获取文本框并修改其内容</title>
</head>
<body>
<script language="javascript">
 <!--
 function c1()
 {
 var t=document.getElementById("txt");
 t.value="www.jb51.net 修改文本内容"
 }
 -->
</script>
<input type="text" id="txt" value="初始文本内容" size="30"/>
<input type="button" value="更改文本内容" name="btn" onclick="c1();" />
</body>
</html>
Copy after login
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to the php Chinese website

Others

related articles! Recommended reading:

Detailed explanation of the steps of props passing data

What are the basic algorithms of Js


How to view and modify the document date and document size


The above is the detailed content of Use JS to manipulate input text box content. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template