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

Sample code for passing value default value using js_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:36:311041browse

The requirements and code are as follows:

"This is my code:"

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

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)
f2868a75e5cdc382115b70981808cb59It 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>

Effect:



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

Statement:
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