如何从表单元素中删除按钮? (JavaScript的)

时间:2011-03-31 18:31:14

标签: javascript

我有这个HTML

<form id="form">

<input id="deleteNumber" name="del" type="hidden" />
<input id="addAddress" name="addAddress" type="hidden" />

...
...
...

<a href="javascript:deleteAddress();" class="deleteItem"/></a>
<a href="javascript:addNextAddress()">Add address </a>
</form>

<script type="text/javascript">
function addNextAddress() {
    var parent = document.getElementById('form');
    var child = document.getElementById('form').del;
    perent.removeChild(child);
    document.getElementById('form').submit();   
}
</script>
<script type="text/javascript">
function deleteAddress() {
    var r=confirm(text);
    if (r == true) {
        var parent = document.getElementById('form');
        var child = document.getElementById('form').addAddress;
        perent.removeChild(child);
        document.getElementById('form').submit();
    }
}
</script>

我得到js错误:

  

未捕获的ReferenceError:perent不是   定义

有人可以帮忙吗?

3 个答案:

答案 0 :(得分:2)

这个功能只是一个错字:

function addNextAddress() {
    var parent = document.getElementById('form');
    var child = document.getElementById('form').del;
    perent.removeChild(child);//<-- change perent to parent
    document.getElementById('form').submit();   
}

答案 1 :(得分:1)

立即尝试

var parent = document.getElementById('form');
var child = document.getElementById('form').addAddress;
parent.removeChild(child);
document.getElementById('form').submit();

或将Parent更改为parent:)

答案 2 :(得分:0)

perent.removeChild(child)更改为parent.removeChild(child)

你有拼写错误 - perent未在代码中的任何位置定义,这就是为什么你看到“perent未定义”。