这是我用来创建新文本框的javascript。
<script language="javascript">
var counter3 = 0;
function addRow() {
var mainContainer = document.getElementById('my_div');
var newDiv = document.createElement('div');
var newQuaText = document.createElement('input');
newQuaText.type = "text";
newQuaText.name = "qua[]";
var newDelButton = document.createElement('input');
newDelButton.type = "button";
newDelButton.value = "-";
newDiv.appendChild(newQuaText);
newDiv.appendChild(newDelButton);
mainContainer.appendChild(newDiv);
counter3++;
newDelButton.onclick = function() {
mainContainer.removeChild(newDiv);
counter3--;
}
}
</script>
</head>
我的HTML代码
<body>
<div id='wrapper'>
<?php
include 'nav.html';
?>
<div id="page-wrapper">
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">Test</h1>
</div>
<!-- /.col-lg-12 -->
</div>
<!-- /.row -->
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">
Add New Slip
</div>
<div class="panel-body">
<div class="row">
<div class="col-lg-6">
<form role="form" method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<div id="my_div">
<input type = "text" class="form-control" name="qua[]" />
<input type="button" class="btn btn-block" value="Add Row" id="Newrow" onclick="addRow()" />
</div>
<input type="submit" name="submit" value="Save"/>
<input type="reset" name="reset" value="Cancel"/>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
在使用javascript函数创建几个文本框之后,这是我用来向表中插入数据的php代码。
$ value){
$ values = mysqli_real_escape_string($ value);
$ query =“INSERT INTO test
(Quantity
)VALUES('$ values')”;
$ inser_query = mysqli_query($ dbcon,$ query);
}
}
}
?>
</body>
</html>
当我运行此代码时,插入表测试的值始终为“0”。为什么我无法从使用addrow()创建的文本框中获取值?