php
  • javascript
  • 2013-04-05 62 views -3 likes 
    -3

    我有一個簡單的html頁面,其中包含一個javascript函數,它添加了行,但是當我嵌入到我的php頁面時,它不會執行。這是onclick函數不起作用。另一個按鈕正常工作。我不知道爲什麼。我對編程相當陌生。Javascript函數不會在php頁面執行

     $content .=" 
        <html> 
    <head> 
    <title>Add Items To Repair</title> 
    <script language='javascript'> 
    row_no=0; 
    function addRow(tbl,row){ 
    row_no++; 
    if (row_no<=20){ 
    if (row_no>=10){ 
    var textbox = row_no+'.)<input type='text' size = '2' maxlength= '2' name= quantity[]>';} 
    if (row_no<10){ 
    var textbox = row_no+'. )<input type='text' size = '2' maxlength= '2' name= quantity[]>';} 
    var textbox2 = '<input type='text' size = '100' maxlength= '100' name= desc[]>'; 
    var textbox3 = '<input type='text' size = '20' maxlength= '20' name= productno[]>'; 
    var textbox4 = '<input type='text' size = '20' maxlength= '20' name= issue[]>'; 
    var tbl = document.getElementById(tbl); 
    var rowIndex = document.getElementById(row).value; 
    var newRow = tbl.insertRow(row_no); 
    var newCell = newRow.insertCell(0); 
    newCell.innerHTML = textbox; 
    var newCell = newRow.insertCell(1); 
    newCell.innerHTML = textbox2; 
    var newCell = newRow.insertCell(2); 
    newCell.innerHTML = textbox3; 
    var newCell = newRow.insertCell(3); 
    newCell.innerHTML = textbox4; 
    
    } 
    if (row_no>12){ 
    alert ('Too Many Items. Limit of 12.'); 
    } 
    } 
    
    
    </script> 
    
    </head> 
    
    
    <body> 
    <form name='invoice' method='post' action='insert.php'> 
    
    <input type='submit' value='Create Repair Ticket'> 
    <input type='button' name='Button' value='Add Items to Repair Ticket' onClick='addRow('table1','row1')'> 
    <table width='1000' border='0' cellspacing='0' cellpadding='2' id='table1'> 
    <th><center>QTY</th> 
    <th>Item Description</th> 
    <th>ProductNumber</th> 
    <th>Issue</th> 
    </center> 
    <tr id='row1'> 
    </tr> 
    </table> 
    
    <table align='center' width='80%'> 
         <tr> 
          <td align='right'><input type='submit' name='checkin' value='Submit'></td><td><input type='reset' name='reset' value='Reset'></td> 
         </tr> 
        </table> 
    </form> 
    </body> 
    </html> 
    "; 
    
    +0

    你需要逃避你的一些報價。 'onClick ='addRow('table1','row1')''會導致語法錯誤。 – jbabey 2013-04-05 12:14:05

    +0

    瀏覽器的錯誤控制檯說什麼? – Oswald 2013-04-05 12:14:15

    回答

    1

    替換:

    <input type='button' name='Button' value='Add Items to Repair Ticket' onClick='addRow(\'table1\',\'row1\')'> 
    
    0

    您正在嵌套您的報價。

    變化:

    <input type='button' name='Button' value='Add Items to Repair Ticket' onClick=**'**addRow(**'**table1**'**,'row1**'**)**'**> 
    

    要:

    <input type='button' name='Button' value='Add Items to Repair Ticket' onClick='addRow(\"table1\",\"row1\")'> 
    
    相關問題