How to dynamically add columns in JavaScript _ javascript skills

Source: Internet
Author: User
This article mainly introduces the method of adding columns dynamically in JavaScript. The example analyzes the skills of using javascript to operate table forms, which has some reference value, for more information about how to dynamically add columns in JavaScript, see the example in this article. Share it with you for your reference. The specific implementation method is as follows:

/***** Dynamically add the table column * @ param result */function addRow (resultJson) {/* var temp = []; temp = $. grep (arr, function (val, key) {if (val. indexOf ('C ')! =-1) return true; // if the [invert] parameter is not set or is false, $. grep only collects the array elements returned by the callback function. // otherwise, the [invert] parameter is true, $. the grep collection callback function returns an array element of false}, false); console. dir (temp); */if (resultJson! = "") {Var cv_arr = new Array (); var date_arr = new Array (); // parse the data source and parse it into the date and result $ that can be recognized by the program. each (resultJson, function (index, val) {if (val ['Parser _ schedule']! = Null) {cv_arr.push (val ['Parser _ schedule']); var temp_data = val ['Parser _ schedule']. split (","); for (I = 0; I
 
  
"+ Date_arr [I] +""); $ (" # Mytable tbody tr "). append ("-");} Var rowNum_arr = new Array (); // obtain the total number of rows for (I = 0; I <$ (" # mytable "). find ("tr "). length; I ++) {// obtain the value of the third column in each row. The first two columns of the table are hidden, the third column starts to judge whether there is data var str =$ ("# mytable tbody "). find ("tr "). eq (I); var std = str. find ("td "). eq (2); // record when no value exists and obtain the row number if ($. trim (std. text ()). length <1) {rowNum_arr.push (I);} else {// optional (std;.html ("") ;}// set TD information for (I = 0; I
  
   

I hope this article will help you design javascript programs.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.