我在函数中有这个代码:
tableFields = tableFields.children;
for (item in tableFields) {
// Do stuff
}
Run Code Online (Sandbox Code Playgroud)
根据tableFields的console.log,我得到一个数组,因为我认为我需要做.循环中的console.log项返回undefined.我需要做什么来遍历tableFields并将每个对象插入表中?
tableFields的控制台日志:
HTMLCollection[label, input, label, input 25, label, input, input, input Remove]
0
label
1
input
2
label
3
input 25
4
label
5
input
6
input
7
input Remove
description[]
input
hours[]
input
invoice_number
input
getlength
8
rate[]
input 25
item
item()
iterator
iterator()
namedItem
namedItem()
__proto__
HTMLCollectionPrototype { item=item(), namedItem=namedItem(), iterator=iterator()}
Run Code Online (Sandbox Code Playgroud)
这是我到目前为止的整个代码部分:
$this->title("Test");
$this->defaultMenu();
$select = "";
$names = Customer::getNames();
foreach ($names as $id => …Run Code Online (Sandbox Code Playgroud) 我正在开发一个发票系统和我的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}');" >
Run Code Online (Sandbox Code Playgroud)
所有值都为null,因为没有创建.在Firebug中我收到错误"SyntaxError:unterminated string literal".我不知道解决这个问题需要什么.导致错误的行是:
<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" …Run Code Online (Sandbox Code Playgroud)