Home > Web Front-end > JS Tutorial > Sample code for passing value default value using js_javascript skills

Sample code for passing value default value using js_javascript skills

WBOY
Release: 2016-05-16 16:36:31
Original
1060 people have browsed it

The requirements and code are as follows:

"This is my code:"

<input type="text" id="price2" value="333"/>
<input type="text" id="trueprice" value="" />
Copy after login
<script type="text/javascript">
document.getElementById("price2").onkeyup = function() {
document.getElementById("trueprice").value = this.value;
}
</script>

Copy after login

Question: When you open this page now, the value of trueprice is empty by default. How can you make trueprice the same as price2 when you open this page by default? (price2 is a dynamic value)
It is fixed and cannot be modified

A simple implementation of mine:

<!DOCTYPE HTML>

<html>

<head>

<meta http-equiv="content-type" content="text/html;charset=utf-8">

<title>Test</title>

</head>

<body>

<input type="text" id="price2" value="333" onkeyup="test(this.value);"/>

<input type="text" id="trueprice" value="" />

<script type="text/javascript">

var price2 = document.getElementById("price2").value;

document.getElementById("trueprice").value = price2;

function test (defaultVal) {

document.getElementById("trueprice").value = defaultVal;

}

</script>

</body>

</html>
Copy after login

Effect:



The content entered in the first text box can be synchronized to the second text box

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