PHP Implementation Click the Add button to add a single line of items and insert all the contents into the database
:
Html+jquery:
<HTML> <Head> <Metahttp-equiv= "Content-type"content= "Text/html;charset=utf-8"> <Scriptlanguage= "JavaScript"type= "Text/javascript"src= "Jquery.min.js"></Script> <Scripttype= "Text/javascript"> $(function(){ $(': Button[name=add]'). Click (function() {inserttr (); }) $('Button[name=del]'). Click (function(){ $( This). Parents ('TR'). Remove (); }) $(': Button[name=delall]'). Click (function(){ $('. Itme'). Remove (); }) }) varGradei=1; functioninserttr () {varHTML="'; HTML+='<tr class= "Itme" ><td><input type= "text" Name= "data[time][]" ></td>'; HTML+='<td><input type= "Radio" name= "data[grade]['+Gradei+'] "value=" 1 "> Good <input type=" Radio "name=" data[grade]['+Gradei+'] "value=" 2 "> Very good </td>'; HTML+='<td><select name= "data[type][" ><option value= "excellent student" > excellent student </option><option value= "again honoured "> Again honoured </option></select></td>'; HTML+='<td><button name= "del" > Delete </button></td></tr>'; $('#tab'). append (HTML); $('Button[name=del]'). Click (function(){ $( This). Parents ('TR'). Remove (); }) Gradei++; } </Script> </Head> <Body> <formAction= "exe.php"Method= "POST"name= "F1"> <Tablewidth= "500px"ID= "tab"> <TR><th>Date</th><th>Level</th><th>Kinds</th><th>Operation</th></TR> <TRclass= "Itme"> <TD><inputtype= "text"name= "data[time][]"></TD> <TD><inputtype= "Radio"name= "Data[grade][0]"value= "1">Good<inputtype= "Radio"name= "Data[grade][0]"value= "2">Very good</TD> <TD><Selectname= "data[type][]"><optionvalue= "Excellent student">Excellent student</option><optionvalue= "Again honoured">Again honoured</option></Select></TD> <TD><Buttonname= "Del">Delete</Button></TD> </TR> </Table> <Div><inputtype= "Submit"name= "Sub"value= "Save" /><inputtype= "button"name= "Delall"value= "Delete all"><inputtype= "button"name= "Add"value= "Add"></Div> </form> </Body> </HTML>
exe.php
<? php $arr _time=$_post[' data ' [' time ']; $arr _grade=$_post[' data ' [' Grade ']; $arr _type=$_post[' data ' [' type ']; for ($i =0; $i <count ($arr _time); $i + +) { $insert [$i] [' Time ']= $arr _time[$i]; $insert [$i] [' Grade ']= $arr _grade[$i]; $insert [$i] [' type ']= $arr _type[$i]; } echo "<pre>"; Print_r ($insert); echo "</pre>"; /* Each data is a data array ( [0] = = Array ([time] + = November 7, 2014 15:50:18 [grade] + 1 [Type] = > Again honoured ) [1] = = Array ( [TIME] = November 7, 2014 15:50:24 [Grade] = 2 [Type] = > Excellent student ) [2] = = Array ( [TIME] = November 7, 2014 15:50:27 [Grade] = 1 [Type] = > Again honoured ) ) * /?>
PHP Implementation Click the Add button to add a single line of items and insert all the contents into the database