用javascript如何获得文本区域的内容

来源:百度知道 编辑:UC知道 时间:2024/05/11 03:55:37
比如获得文本框的内容是input.value,请问获得文本区域的内容是什么啊?

或者给出这样的代码也行:当文本区域获得焦点时,内容为空,当失去焦点时,内容又恢复成原有的。

哪位高手指点一下,最好说的详细点!非常感谢!

你的设计不大实用,帮你升级了一下;
只有当区域的内容为初始内容时候获取焦点才将其内容置为空,
只有当区域输入空内容时候失去焦点才将内容置为初始内容,否则保留当前内容:
代码如下:
<!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=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
window.onload=function(){
var prev=null;
var oInfor=document.getElementById('test').value;
document.getElementById('test').onfocus=function(){
var infor=document.getElementById('test').value;
if(infor==oIn