javascript - Adding + sign to a table, revealing more rows -
Problem: I'm totally new to the front-end development, I am using JSONP and AJAX Using a table with some data about university course, I am able to create a table. However, I have to add a new column to sign a + one at the beginning of each line. When this is clicked, a new group of data describing all the students of the course opens, and gets + one - I do not yet see the best way to do this. Any advice?
Code:
& lt ;! DOCTYPE html public "- // W3C // DTT XHTML 1.0 Transcriptional // N" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" & gt; & Lt; Html xmlns = "http://www.w3.org/1999/xhtml" & gt; & Lt; Top & gt; & Lt; Meta http-equiv = "content-type" content = "text / html; charset = UTF-8" /> & Lt; Title & gt; Request json test & lt; / Title & gt; & Lt; Script src = "http://code.jquery.com/jquery-1.5.js" & gt; & Lt; / Script & gt; & Lt; Script src = "json-jquery.js" type = "text / javascript" & gt; & Lt; / Script & gt; & Lt; Script type = "text / javascript" & gt; $ (Document) .ready (function () {$ .ajax ({url: 'http: //xx.xxx.xxx.xx/getCourses.php', datatype: 'jsnp', jesenpie callback: "curriculum", success : Function (Data) {Drawing (Data);}}};}); Function Datababel (Data for {var i = 0; i & lt; data courses.length; i ++) {Driving (Data Quoters [i]);}} Function Drawer (row data) {var row = $ ("& lt; tr / & gt;") $ ("# dataTable"). Attachment (line); Row.append ($ (" & Lt; td & gt; "+ rowData.courseName +" & lt; / td & gt; ")); Row.append ($ (" & lt; td> "+ rowData.start +" & lt; /; & Quot;)); Row.append ($ ("& lt; td>" + rowData.end + "& lt; / td & gt;")); Row.append ($ (" Lt; td & gt; "+ rowData.lecturerName +" & lt; / td & Gt; "));} & lt; / script> gt; & lt; / head & gt; & lt; body & gt; table id =" datatable "& gt; & lt; tr & gt; Lt; th & gt; Column 1 Th> Column 2 Th & gt; Column 3 & lt; / th & gt; & Lt; th & gt; Column 4 & lt; / th & gt; & lt; / tr & gt; & lt; / table & gt; & Lt; / Body & gt; & Lt; / Html & gt;
You can choose to change the content of your button or just a class Turn it up and change CSS display visualization. Apply a general class to the elements of the event binding selector simplicity.
I will add the data attribute containing a course identifier, which is essential for student requesting the next request.
Function drawer (row data) {var button = '& lt; Element Data-courseID = "'+ rowData.id +'" class = "data-button" & gt; + & Lt; / AnyElement & gt; '; Var line = $ ("& lt; tr / & gt;") line .append ('& lt; td & gt;' + button + ';); / * No "$ ()" * / * Attach other cells * * / / * after attachment to the DOM, makes for less DOM entry * / $ ("# dataTable"). Append (line); }
Then add an event handler to the button in your ready handler. This
refers to the current example within the event handler.
$ ("# dataTable"). ('Click', '.data-button', function) {/ * text change method * / $ (this) .text (function (_, curtext) {return query === '+'? '- ':' + ';}); / * Class Change * / $ (This) .toggleClass ('Active'); / * Get data * / var id = $ (this). Data ('courseId'); / * Call APIs based on IDE * /})
Comments
Post a Comment