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

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

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

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

<!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="">中央情報(bào)局</a>:中央情報(bào)局</div>
  <div class="time">2014年5月4日21:56</div>
  <div class="replyButton">
   <input type="button" id="submitButton" value="回復(fù)" 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í)測試用函數(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 | $ )判斷后面是否有空格 兩個(gè)感嘆號(hào)為轉(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用法詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-07-07
  • uniapp解決軟鍵盤彈出問題方法詳解

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

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

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

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

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

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

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

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

    JS中多步驟多分步的StepJump組件實(shí)例詳解

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

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

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

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

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

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

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

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

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

最新評論

犍为县| 微山县| 宝兴县| 抚远县| 黑河市| 海兴县| 嵩明县| 常德市| 青阳县| 崇礼县| 广元市| 元江| 云梦县| 泰顺县| 珠海市| 中江县| 库车县| 正镶白旗| 鲁甸县| 垣曲县| 灌云县| 常德市| 怀柔区| 诏安县| 彭州市| 通渭县| 长治县| 翼城县| 深水埗区| 准格尔旗| 冀州市| 太保市| 襄垣县| 海原县| 牟定县| 广东省| 德惠市| 台湾省| 沙坪坝区| 保德县| 客服|