从textarea获取数据并在javascript中的div上显示此数据 [英] get a data from textarea and show this data on div in javascript

查看:54
本文介绍了从textarea获取数据并在javascript中的div上显示此数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了以下代码来从用户输入的textarea中获取数据,并在单击确定"按钮后在div(odiv3)上显示该数据;

它可以正常工作,但是那些粘贴在div上的数据在单击确定"按钮后将变得不可见.
我如何在div上显示此数据????/

i have written following code to get the data from textarea those input by user and show that data on the div(odiv3) after clicking on "ok" button;

its working but the data those paste on div its going unvisible after clicking on button o"ok".

How i can show this data on div ????/

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Three Div Tags</title>
<script type="text/javascript">
   function addContent(odiv3, data) 
   {
      alert("ddddd");
     document.getElementById(odiv3).innerHTML = data;
 }	 
  </script>
<style>
#odiv1{
	margin:3px;
	
	background-color:#333333;
	height:400px;
	width:460px;
}
#odiv2{
background-color:#0066FF;
margin-left:8px;
    margin-top:15px;  
	
	height:200px;
	width:200px;
	float:left;
		
}
#odiv3{ overflow:Auto;
margin-top:12px;
  
   float:right;
	background-color: #00FF66;
	height:340px;
	width:200px;
	 
}
</style>

</head>

<body>
<form name="form">
<div id="odiv1"><p align="left">odiv1</p>
<div id="odiv2">div2<br>
  <textarea  id="text" cols="20"   rows="5"></textarea>
</br></div>
<div id="odiv3">odiv3<br>
  </br></div>
</div>
<input type="submit" value="ok"  önclick="addContent('odiv3', document.form.text.value);" />
   </form>
</body>
</html>

推荐答案

您的name="text"在哪里?毕竟,在jQuery中完成所有操作即可消除烦恼并开始编程.
您将使用jQuery 选择器获得元素,并使用操纵方法组添加/修改内容/属性:
http://api.jquery.com/category/selectors/ [ http://api.jquery.com/category/manipulation/ [ http://en.wikipedia.org/wiki/Jquery [ http://jquery.com/ [ ^ ].

从这里开始:
http://docs.jquery.com/Tutorials:How_jQuery_Works [ http://docs.jquery.com/Tutorials [ http://docs.jquery.com/Main_Page [
Where is your name="text"? After all, do it all in jQuery to stop worrying and start programming.
You would get the elements using jQuery selectors and add/modify content/properties using the manipulation group of methods:
http://api.jquery.com/category/selectors/[^],
http://api.jquery.com/category/manipulation/[^].

Please see:
http://en.wikipedia.org/wiki/Jquery[^],
http://jquery.com/[^].

Start here:
http://docs.jquery.com/Tutorials:How_jQuery_Works[^],
http://docs.jquery.com/Tutorials[^],
http://docs.jquery.com/Main_Page[^].

Write less, do more…

—SA


<script  type ="text/javascript" language ="javascript"  >
function showDiv1()
{
document.getElementById('Div1').innerHTML=document.getElementById('TextArea1').value;
return false;
}
    </script>


<input type="submit" id="btn" value="ok" onclick="return showDiv1();" />



这样使用,我认为它将解决您的问题.我已经检查过了.它正在工作.



use like this i think it will solve ur problem. i have checked it. it is working.


这篇关于从textarea获取数据并在javascript中的div上显示此数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆