最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

JavaScript實現(xiàn)添加、查找、刪除元素

 更新時間:2015年07月02日 11:15:45   投稿:hebedich  
這篇文章主要匯總介紹了JavaScript實現(xiàn)添加、查找、刪除元素的方法,十分的簡單實用,有需要的小伙伴可以參考下。

代碼很簡單,這里就不多廢話了。

<!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>
//顯示文本框的函數(shù)
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;
}
//隱藏文本框的函數(shù)
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;
}

//下面為調(diào)試時測試用函數(shù),做完后就沒用了,但也是很經(jīng)典的一段代碼,就留在這里了。
function showNode()
{
  var i = 4;
  submitButton = document.getElementById('submitButton');
  i = submitButton.parentNode.parentNode.getElementsByTagName("INPUT").item(1).value;
  alert(i);
}
</script>
</body>
</html>

示例二:

window.onload = function(){ 
var gaga = document.getElementById( "gaga" ); 
addClass( gaga,"gaga1" ) 
addClass( gaga,"gaxx" ); 
removeClass( gaga,"gaga1" ) 
removeClass( gaga,"gaga" ) 
function hasClass( elements,cName ){ 
return !!elements.className.match( new RegExp( "(\\s|^)" + cName + "(\\s|$)") ); // ( \\s|^ ) 判斷前面是否有空格 (\\s | $ )判斷后面是否有空格 兩個感嘆號為轉(zhuǎn)換為布爾值 以方便做判斷 
}; 
function addClass( elements,cName ){ 
if( !hasClass( elements,cName ) ){ 
elements.className += " " + cName; 
}; 
}; 
function removeClass( elements,cName ){ 
if( hasClass( elements,cName ) ){ 
elements.className = elements.className.replace( new RegExp( "(\\s|^)" + cName + "(\\s|$)" )," " ); // replace方法是替換 
}; 
}; 
};

以上所述就是本文的全部內(nèi)容了,希望大家能夠喜歡。

相關(guān)文章

  • JavaScript中window和document用法詳解

    JavaScript中window和document用法詳解

    這篇文章主要介紹了JavaScript中window和document用法詳解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-07-07
  • uniapp解決軟鍵盤彈出問題方法詳解

    uniapp解決軟鍵盤彈出問題方法詳解

    這篇文章主要為大家介紹了uniapp解決軟鍵盤彈出問題方法詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-07-07
  • 原生JS實現(xiàn)的碰撞檢測功能示例

    原生JS實現(xiàn)的碰撞檢測功能示例

    這篇文章主要介紹了原生JS實現(xiàn)的碰撞檢測功能,涉及javascript鼠標事件響應(yīng)及頁面圖形坐標位置運算、檢測相關(guān)操作技巧,需要的朋友可以參考下
    2018-05-05
  • Js md5加密網(wǎng)頁版MD5轉(zhuǎn)換代碼

    Js md5加密網(wǎng)頁版MD5轉(zhuǎn)換代碼

    Js實現(xiàn)網(wǎng)頁上的MD5加密功能,將文字轉(zhuǎn)換為MD5字符,本代碼調(diào)用簡單,你可以新建一個網(wǎng)頁,將此網(wǎng)頁上傳到你的服務(wù)器上,用戶瀏覽網(wǎng)頁,就可實現(xiàn)MD5加密轉(zhuǎn)換功能,用戶可方便查詢?nèi)我蛔址腗D5碼,很不錯的功能
    2013-03-03
  • javascript實現(xiàn)C語言經(jīng)典程序題

    javascript實現(xiàn)C語言經(jīng)典程序題

    這篇文章主要介紹了javascript實現(xiàn)C語言經(jīng)典程序題的解題思路,感興趣的小伙伴們可以參考一下
    2015-11-11
  • JS中多步驟多分步的StepJump組件實例詳解

    JS中多步驟多分步的StepJump組件實例詳解

    這篇文章主要介紹了JS中多步驟多分步的StepJump組件實例詳解的相關(guān)資料,需要的朋友可以參考下
    2016-04-04
  • JS實現(xiàn)不規(guī)則TAB選項卡效果代碼

    JS實現(xiàn)不規(guī)則TAB選項卡效果代碼

    這篇文章主要介紹了JS實現(xiàn)不規(guī)則TAB選項卡效果代碼,通過簡單的JavaScript響應(yīng)鼠標事件動態(tài)變換元素樣式實現(xiàn)不規(guī)則選項卡效果,非常具有實用價值,需要的朋友可以參考下
    2015-09-09
  • 使用Bootstrap和Vue實現(xiàn)用戶信息的編輯刪除功能

    使用Bootstrap和Vue實現(xiàn)用戶信息的編輯刪除功能

    這篇文章主要介紹了使用Bootstrap和Vue實現(xiàn)用戶信息的編輯刪除功能,需要的朋友可以參考下
    2017-10-10
  • JavaScript閉包的簡單應(yīng)用

    JavaScript閉包的簡單應(yīng)用

    這篇文章主要為大家詳細介紹了JavaScript閉包的簡單應(yīng)用,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-09-09
  • js實現(xiàn)模態(tài)窗口增加與刪除

    js實現(xiàn)模態(tài)窗口增加與刪除

    這篇文章主要為大家詳細介紹了js實現(xiàn)模態(tài)窗口增加與刪除,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-07-07

最新評論

东阳市| 三都| 安平县| 吴江市| 富蕴县| 衡阳县| 柯坪县| 武威市| 古田县| 潼关县| 绍兴市| 团风县| 翼城县| 韩城市| 晋城| 绥棱县| 临沭县| 巩留县| 遵化市| 资讯 | 东丽区| 东乌珠穆沁旗| 石台县| 阳西县| 福建省| 塘沽区| 桑日县| 桑植县| 洪湖市| 宁阳县| 松原市| 剑河县| 井陉县| 招远市| 鄂州市| 科技| 长岛县| 洛南县| 常熟市| 大余县| 合川市|