DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> 關於JavaScript >> js實現文本框中輸入文字頁面中div層同步獲取文本框內容的方法教程
js實現文本框中輸入文字頁面中div層同步獲取文本框內容的方法教程
編輯:關於JavaScript     

本文實例講述了js實現文本框中輸入文字頁面中div層同步獲取文本框內容的方法。分享給大家供大家參考。具體實現方法如下:

代碼如下:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>文本框中輸入文字,頁面中div層同步獲取文本框內容</title>
<style>
textarea{width:300px;height:150px; border:1px solid #CCC; font-size:12px; color:#000;}
p{ padding-left:30px; text-indent:-30px;width:270px;height:250px; border:1px solid #900; margin-top:50px; font-size:12px; color:#F00; line-height:21px; overflow:hidden}
</style>
<script type="text/javascript">
 function SwapTxt()
  {
      var txt = document.getElementById("eml").value;
      document.getElementById("lyny").innerHTML=txt;
  }
</script>
</head>
<body>
  <textarea name="" cols="" rows="" class="loe_hk10" id="eml" onkeyup="SwapTxt()"></textarea>
  <p id="lyny">代碼家園提示:請在上面的文本框中輸入文字,如www.cnblogs.com</p>
</body>
</html>

希望本文所述對大家的javascript程序設計有所幫助。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved