Javascript函数不会在php页面中执行[关闭]

Javascript函数不会在php页面中执行[关闭]

问题描述:

I have simple html page which contains a javascript function which adds rows, but when i embed into my php page it does not execute. It is the onclick function which does not work. The other button works fine. i'm at a loss to why. I'm fairly new to programming.

        $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>
"; 

replace with :

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

You are nesting your quotes.

Change:

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

To:

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