我正在开发一个发票系统,我的 mvc 框架中的控制器现在使用单引号括起来的字符串。我是 javascript 的新手,但我无法避免它。我有在 window.onload 声明中工作和验证的函数,但表单内的相同声明会产生错误。html输出为:
onclick="verifyAccount('{"1":null,"2":null,"3":null,"4":null,"5":null,"8":null,"9":null,"10":null,"21":null,"22":null}');" >
所有值都是空的,因为没有创建任何值。在 Firebug 中,我收到错误“SyntaxError:未终止的字符串文字”。我不知道需要什么来解决这个问题。导致错误的行是:
<input type="radio" name="account" id="account" onclick="verifyAccount(\''.$accounts.'\');" >
$form = '
<script type="text/javascript">
window.onload = function() {
document.getElementById("addLabor").onclick = function(){ addLabor("labor"); }
document.getElementById("addPart").onclick = function(){ addPart("parts"); }
document.getElementById("addAdjustment").onclick = function(){ addAdjustment("adjustments"); }
document.getElementById("customer_id").onchange = function() { verifyAccount(\''.$accounts.'\'); }
addLabor("labor");
}
</script>
$form = '
<script type="text/javascript">
window.onload = function() {
document.getElementById("addLabor").onclick = function(){ addLabor("labor"); }
document.getElementById("addPart").onclick = function(){ addPart("parts"); }
document.getElementById("addAdjustment").onclick = function(){ addAdjustment("adjustments"); }
document.getElementById("customer_id").onchange = function() { verifyAccount(\''.$accounts.'\'); }
addLabor("labor");
}
</script>
<form method="POST" class="formTable" id="addInvoice" action="/invoices/save"
onsubmit="return(validate());">
<table class="buttons" >
<tr>
<td><input type="button" id="addLabor" value="Add labor"/></td>
<td><input type="button" id="addPart" value="Add part"/></td>
<td><input type="button" id="addAdjustment" value="Adjust"/></td>
<td><input type="submit" name="Save" value="Save" /></td>
</tr>
</table>
<table id="invoiceTable">
<tr>
<td><label>Date:</label></td>
<td><input type="text" id="date" name="date" maxlength="10" size="4" />
<a href="javascript:NewCal(\'date\',\'MMDDYYYY\')">
<img src="/images/cal.gif" width="16" height="16" alt="Pick a date"></a>
</td>
</tr>
<tr>
<td><label>Use Account?:</label></td>
<td><input type="radio" name="account" id="account" onclick="verifyAccount(\''.$accounts.'\')" ></td>
</tr>
<tr>
<td><label>Work Order Number:</label></td>
<td><input type="text" name="number" id="number" maxlength="8" size="6" /></td>
</tr>
<tr>
<td><label>Customer:</label></td>
<td><select name="customer_id" id="customer_id" >'.$select.'</select></td>
</tr>
<tr>
<td><label>Job Name:</label></td>
<td><input type="text" name="job_name" id="job_name" /></td>
</tr>
</table>
<table id="labor"></table>
<table id="parts"></table>
<table id="adjustments"></table>
<table id="payment"></table>
</form>';
$this->component($form);
<form method="POST" class="formTable" id="addInvoice" action="/invoices/save"
onsubmit="return(validate());">
<table class="buttons" >
<tr>
<td><input type="button" id="addLabor" value="Add labor"/></td>
<td><input type="button" id="addPart" value="Add part"/></td>
<td><input type="button" id="addAdjustment" value="Adjust"/></td>
<td><input type="submit" name="Save" value="Save" /></td>
</tr>
</table>
<table id="invoiceTable">
<tr>
<td><label>Date:</label></td>
<td><input type="text" id="date" name="date" maxlength="10" size="4" />
<a href="javascript:NewCal(\'date\',\'MMDDYYYY\')">
<img src="/images/cal.gif" width="16" height="16" alt="Pick a date"></a>
</td>
</tr>
<tr>
<td><label>Use Account?:</label></td>
<td><input type="radio" name="account" id="account" onclick="verifyAccount(\''.$accounts.'\')" ></td>
</tr>
<tr>
<td><label>Work Order Number:</label></td>
<td><input type="text" name="number" id="number" maxlength="8" size="6" /></td>
</tr>
<tr>
<td><label>Customer:</label></td>
<td><select name="customer_id" id="customer_id" >'.$select.'</select></td>
</tr>
<tr>
<td><label>Job Name:</label></td>
<td><input type="text" name="job_name" id="job_name" /></td>
</tr>
</table>
<table id="labor"></table>
<table id="parts"></table>
<table id="adjustments"></table>
<table id="payment"></table>
</form>';
$this->component($form);