Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/396.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何删除xmlhttp请求项_Javascript_Forms_Xmlhttprequest - Fatal编程技术网

Javascript 如何删除xmlhttp请求项

Javascript 如何删除xmlhttp请求项,javascript,forms,xmlhttprequest,Javascript,Forms,Xmlhttprequest,我正在使用JavaScript和xmlhttp将另一行项目添加到表单中。我试图弄清楚,如果用户多次按下“添加行项目”按钮,如何删除行项目,以便表单不会尝试从不必要的行项目中发布空值 <script type="text/javascript"> var counter = 1; function addInput(div){ xmlhttp=new XMLHttpRequest(); xmlhttp.onreadystatechange =

我正在使用JavaScript和xmlhttp将另一行项目添加到表单中。我试图弄清楚,如果用户多次按下“添加行项目”按钮,如何删除行项目,以便表单不会尝试从不必要的行项目中发布空值

<script type="text/javascript">
var counter = 1;
     function addInput(div){
        xmlhttp=new XMLHttpRequest();
        xmlhttp.onreadystatechange = function() {
         if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
          var newdiv = document.createElement(div);
          var splitResponse = xmlhttp.responseText.split( "[BRK]" );
          var firstDropdownContent = splitResponse[0];
          var secondDropdownContent = splitResponse[1];
          newdiv.innerHTML = "<table id='" + (++counter) +"'>
<tr><td><img style='background:#ffffff; float:left; ' src='../../images/spacer_icon.png'>Item " + (counter) + "</td>
<td>Quantity</td>
<td>Description</td>
<td>Amount</td>
<td><img style='background:#ffffff; float:left; ' src='../../images/spacer_icon.png'>Tax Rate</td></tr>
<tr><td width='190'><select name='item[]'><option value='' selected></option>" + (firstDropdownContent) + "</select></td>
<td width='90'><input name='quantity[]' type='text' size='5' /></td>
<td width='440'><input name='description[]' type='text' size='60' /></td>
<td width='120'><input name='amount[]' type='text' size='6' /></td>
<td><select name='taxid[]'><option value='' selected></option>" + (secondDropdownContent) + "</select></td>
<td><button onclick='removeItem('row" + counter + "')'>Remove</button></td></tr></table><br />";

           document.getElementById(div).appendChild(newdiv);
          }
}

xmlhttp.open("GET", "invoicedropdownquery.php", false);
xmlhttp.send();

}
</script>
下面是添加行项目的javascript代码

<script type="text/javascript">
var counter = 1;
     function addInput(div){
        xmlhttp=new XMLHttpRequest();
        xmlhttp.onreadystatechange = function() {
         if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
          var newdiv = document.createElement(div);
          var splitResponse = xmlhttp.responseText.split( "[BRK]" );
          var firstDropdownContent = splitResponse[0];
          var secondDropdownContent = splitResponse[1];
          newdiv.innerHTML = "<table id='" + (++counter) +"'>
<tr><td><img style='background:#ffffff; float:left; ' src='../../images/spacer_icon.png'>Item " + (counter) + "</td>
<td>Quantity</td>
<td>Description</td>
<td>Amount</td>
<td><img style='background:#ffffff; float:left; ' src='../../images/spacer_icon.png'>Tax Rate</td></tr>
<tr><td width='190'><select name='item[]'><option value='' selected></option>" + (firstDropdownContent) + "</select></td>
<td width='90'><input name='quantity[]' type='text' size='5' /></td>
<td width='440'><input name='description[]' type='text' size='60' /></td>
<td width='120'><input name='amount[]' type='text' size='6' /></td>
<td><select name='taxid[]'><option value='' selected></option>" + (secondDropdownContent) + "</select></td>
<td><button onclick='removeItem('row" + counter + "')'>Remove</button></td></tr></table><br />";

           document.getElementById(div).appendChild(newdiv);
          }
}

xmlhttp.open("GET", "invoicedropdownquery.php", false);
xmlhttp.send();

}
</script>

var计数器=1;
函数附加输入(div){
xmlhttp=新的XMLHttpRequest();
xmlhttp.onreadystatechange=函数(){
if(xmlhttp.readyState==4&&xmlhttp.status==200){
var newdiv=document.createElement(div);
var splitResponse=xmlhttp.responseText.split(“[BRK]”);
var firstDropdownContent=splitResponse[0];
var secondDropdownContent=splitResponse[1];
newdiv.innerHTML=”
项目“+(计数器)+”
量
描述
数量
税率
“+(firstDropdownContent)+”
“+(secondDropdownContent)+”
删除
“; document.getElementById(div).appendChild(newdiv); } } open(“GET”,“invoicedropdownquery.php”,false); xmlhttp.send(); }
下面是删除该项的javascript

<script type="text/javascript">
function removeItem(itemId){
    document.getElementById('dynamicInput').removeChild(document.getElementById(itemId));
}
</script>

函数removeItem(itemId){
document.getElementById('dynamicInput').removeChild(document.getElementById(itemId));
}
这是我的添加按钮

<input type="button" value="Add Line Item" onClick="addInput('dynamicInput');">

这是添加行的地方

<div id="dynamicInput"></div>


当我点击删除按钮时,不仅项目没有被删除,整个表单也会发布。我在想,也许有人可以教我如何创建一个可点击的链接,而不是按钮。

您的控制台中是否有任何错误?您能准确地说出哪一行吗?请这样尝试
删除
。使用带反斜杠的引号将其转义。像这样,汤姆就是你问题的答案