亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

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

我的一個簡單實(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>

效果:



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

相關(guān)文章

最新評論