欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

用js傳遞value默認(rèn)值的示例代碼

 更新時(shí)間:2014年09月11日 15:48:02   投稿:whsnow  
這篇文章主要介紹了用js傳遞value默認(rèn)值的簡單實(shí)現(xiàn),很簡單但比較實(shí)用,需要的朋友可以參考下

需求和代碼如下:

“這是我的代碼:”

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

問題:現(xiàn)在打開這個(gè)頁面,trueprice的值默認(rèn)是空的,怎樣才能實(shí)現(xiàn)默認(rèn)打開這個(gè)頁面trueprice就已經(jīng)和price2一樣了呢?(price2是一個(gè)動(dòng)態(tài)的數(shù)值)
<input type=”text” id=”trueprice” value=”” />是固定不可以修改的

我的一個(gè)簡單實(shí)現(xiàn):

<!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>

效果:



在第一個(gè)文本框中輸入的內(nèi)容能同步到第二個(gè)文本框

相關(guān)文章

最新評(píng)論