JavaScript添加、查找、删除元素的一个实例
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>测试文件</title>
<style>
.reply {
width: 500px;
height: 100%;
overflow: hidden;
background-color:#CCC;
margin-top: 10px;
}
.infoArea {
width: 380px;
height: 100%;
overflow: hidden;
}
.words {
width: 380px;
height: auto;
margin: 5px 0px;
float: left;
font-size: 14px;
}
.time {
margin-left: 10px;
margin-bottom: 3px;
width: 150px;
height: 20px;
line-height: 20px;
float: left;
font-family: 楷体;
font-size: 14px;
color: #999;
}
.replyButton {
width: 60px;
height: 20px;
float: left;
margin-bottom: 10px;
}
.replyButton input {
font-size: 12px;
}
#cancelButton {
visibility: hidden;
}
</style>
</head> <body>
<div class="reply">
<div class="infoArea">
<div class="words"><a href="">中央情报局</a>:中央情报局</div>
<div class="time">2014年5月4日21:56</div>
<div class="replyButton">
<input type="button" id="submitButton" value="回复" onClick="showReplyArea(this)" />
</div>
<div class="replyButton">
<input type="button" id="cancelButton" value="取消" onClick="hideReplyArea(this)" />
</div>
</div>
</div>
<script>
//显示文本框的函数
function showReplyArea(src)
{
inputText = document.createElement("DIV");
inputText.className = "inputText";
inputText.style.width = '100%';
inputText.style.height = '75px';
inputText.style.margin = '3px 0';
inputText.style.cssFloat = 'left'; var grandfather = src.parentNode.parentNode.parentNode;
grandfather.appendChild(inputText); form1 = document.createElement("FORM");
form1.action = "";
form1.method = "post";
inputText.appendChild(form1); inputTextArea = document.createElement("TEXTAREA");
inputTextArea.style.width = '380px';
inputTextArea.style.height = '40px';
inputTextArea.style.marginLeft = '60px';
inputTextArea.style.marginTop = '3px';
inputTextArea.style.cssFloat = 'left';
inputTextArea.style.resize = 'none'; textSubmit = document.createElement("INPUT");
textSubmit.type = 'submit';
textSubmit.value = '提交';
textSubmit.style.marginLeft = '80px';
textSubmit.style.cssFloat = 'left'; form1.appendChild(inputTextArea);
form1.appendChild(textSubmit); cancelButton = grandfather.getElementsByTagName("INPUT").item(1);
cancelButton.style.visibility = 'visible';
submitButton = src;
submitButton.disabled = true;
}
//隐藏文本框的函数
function hideReplyArea(src)
{
var grandfather = src.parentNode.parentNode.parentNode;
var inputText = grandfather.getElementsByClassName('inputText').item(0);
grandfather.removeChild(inputText); cancelButton = src;
cancelButton.style.visibility = 'hidden';
submitButton = grandfather.getElementsByTagName("INPUT").item(0);
submitButton.disabled = false;
} //下面为调试时测试用函数,做完后就没用了,但也是很经典的一段代码,就留在这里了。
function showNode()
{
var i = 4;
submitButton = document.getElementById('submitButton');
i = submitButton.parentNode.parentNode.getElementsByTagName("INPUT").item(1).value;
alert(i);
}
</script>
</body>
</html>
JavaScript添加、查找、删除元素的一个实例的更多相关文章
- JavaScript向select下拉框中添加和删除元素
JavaScript向select下拉框中添加和删除元素 1.说明 a 利用append()方法向下拉框中添加元素 b 利用remove()方法移除下拉框中最后一个元素 2.设计源码 < ...
- javascript数组在指定位置添加和删除元素
在JavaScript中,Array对象提供了一个强大的splice()方法,利用这个方法可以达到在数组的指定位置添加和删除元素的目的. 指定位置删除元素 要在指定位置删除元素,可以使用splice( ...
- 顺序表添加与删除元素以及 php实现顺序表实例
对顺序表的操作,添加与删除元素. 增加元素 如下图所示 对顺序列表 Li [1328,693,2529,254] 添加一个元素 111 ,有三种方式: a)尾部端插入元素,时间复杂度O(1); ...
- Arrays.asList () 不可添加或删除元素的原因
Java中奖数组转换为List<T>容器有一个很方便的方法 Arrays.asList(T ... a),我通过此方法给容器进行了赋值操作,接着对其进行 添加元素,却发现会抛出一个(jav ...
- js进阶 9-11 select选项框如何动态添加和删除元素
js进阶 9-11 select选项框如何动态添加和删除元素 一.总结 一句话总结: 二.js进阶 9-11 select选项框如何动态添加和删除元素 1.案例说明 2.相关知识 Select 下拉列 ...
- 4. 理解Update、Enter、Exit 与 添加、删除元素
理解Update.Enter.Exit 与 添加.删除元素 在使用data()绑定数据时,例如:现在我们有一个数组[3,6,9,12,15],我们可以将数组每一项与一个<p>绑定,但是,现 ...
- jQuery_添加与删除元素
一.jQuery添加元素(通过 jQuery,可以很容易地添加新元素/内容.) 1.添加新的 HTML 内容,用于添加新内容的四个 jQuery 方法(都能解析HTML标签): append() - ...
- (转载)php数组添加、删除元素的方法
(转载)http://www.phpgs.com/html/php/phpjichu/20120130440.html 带来一篇php 数组 添加元素.删除元素的方法的文章,有需要的php学习者参考下 ...
- js数组添加或删除元素
var arr = new Array(); arr[] = "aaa"; arr[] = "bbb"; arr[] = "ccc"; ar ...
随机推荐
- Guava学习笔记:Guava新增集合类型-Multimap
在日常的开发工作中,我们有的时候需要构造像Map<K, List<V>>或者Map<K, Set<V>>这样比较复杂的集合类型的数据结构,以便做相应的业 ...
- jquery $(document).ready() 与window.onload
- 在你设计中可能用到的20个杂志 PSD 原型
你是否正在为您的印刷产品找一些现成的原型素材?在这里,我们收集了一组免费的杂志 PSD 素材,必将派上用场.这些原型将给你和你的客户一个先睹为快的产品,在现实生活中看起来如何.所有这些原型提供了可以免 ...
- JavaScript基础系列(变量与类型)
以下内容将JavaScript简称为JS 打开本文时不管你是零基础的初学者还是其他语言的老兵,我都想说程序语言的基础支撑起了整个网络世界,不把这些基础学透之后稍复杂的内容会让你寸步难行. 现在先给编程 ...
- rem在响应式布局中的应用
rem/em/px/pt的基友关系 px 像素相对长度单位,相对于显示器屏幕分辨率而言 em 相对长度单位,根据其父元素来设置字体大小 pt point,是印刷行业常用单位,等于1/72英寸 rem ...
- ABAP可以提高效率的小语法
ADD dobj1 TO dobj2. Effect This statement has the same effect as the statement COMPUTE dobj2 = dobj2 ...
- Linux学习心得之 双显卡、中文输入法及svn初步使用
作者:枫雪庭 出处:http://www.cnblogs.com/FengXueTing-px/ 欢迎转载 Linux学习心得之 双显卡.中文输入法及svn初步使用 1.前言 2.Linux双显卡解决 ...
- iOS从info.plist获取项目的名称及版本号
NSString *executableFile = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundl ...
- pod install 和 pod update的区别
pod install 和 pod update的区别 pod install(下载并安装pod) 1,当pod file文件中有“增加pod,删除pod,修改pod”的操作之后使用. 2,pod i ...
- 你真的了解UIEvent、UITouch吗?
一:首先查看一下关于UIEvent的定义 //事件类型 typedef NS_ENUM(NSInteger, UIEventType) { UIEventTypeTouches, UIEventTyp ...