This article mainly summarizes how to add, search, and delete elements in JavaScript. It is very simple and practical. If you need it, you can refer to it. The code is very simple, so there is not much nonsense here.
Test File
CIA: CIA
May 4, 2014
Script // function of displaying the text box showReplyArea (src) {inputText = document. createElement ("DIV"); inputText. className = "inputText"; inputText. style. width = '000000'; inputText. style. height = '75px '; inputText. style. margin = '3px 0'; inputText.style.css Float = 'left'; var grandfather = src. parentNode. parentNode. parentNode; grandfather. appendChild (inputText); form1 = document. createElement ("FORM"); form1.acti On = ""; form1.method = "post"; inputText. appendChild (form1); inputTextArea = document. createElement ("TEXTAREA"); inputTextArea. style. width = '0000p'; inputTextArea. style. height = '40px '; inputTextArea. style. marginLeft = '60px '; inputTextArea. style. marginTop = '3px '; inputTextArea.style.css Float = 'left'; inputTextArea. style. resize = 'none'; textSubmit = document. createElement ("INPUT"); textSubmit. Type = 'submit '; textSubmit. value = 'Submit'; textSubmit. style. marginLeft = '80px '; textSubmit.style.css Float = 'left'; form1.appendChild (inputTextArea); form1.appendChild (textSubmit); cancelButton = grandfather. getElementsByTagName ("INPUT "). item (1); cancelButton. style. visibility = 'visable'; submitButton = src; submitButton. disabled = true;} // function used to hide the text box hideReplyArea (src) {var grandfather = sr C. parentNode. parentNode. parentNode; var inputText = grandfather. getElementsByClassName ('inputtext '). item (0); grandfather. removeChild (inputText); cancelButton = src; cancelButton. style. visibility = 'den den '; submitButton = grandfather. getElementsByTagName ("INPUT "). item (0); submitButton. disabled = false;} // The following is the function used for testing during debugging. It will be useless after completion, but it is also a classic piece of code and will be left here. Function showNode () {var I = 4; submitButton = document. getElementById ('submitclick'); I = submitButton. parentNode. parentNode. getElementsByTagName ("INPUT "). item (1 ). value; alert (I);} script
Example 2:
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 | ^) determine whether there is a space (\ s | $) in the front to determine whether there are spaces in the back to convert the Two exclamation points into boolean values for easy judgment}; 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 method: replace };};};
The above is all the content of this article. I hope you will like it.