Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.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 JS函数正在中断其余函数_Javascript_Jquery_Html - Fatal编程技术网

Javascript JS函数正在中断其余函数

Javascript JS函数正在中断其余函数,javascript,jquery,html,Javascript,Jquery,Html,我有一个函数,它可以中断页面上所有其他javascript/jquery 我试图用下面的函数做的是在按下按钮时复制一个div,并将其附加到初始div之后(可以复制到按下的次数),它工作得很好,除了其他所有操作都会中断 我在上面添加了代码片段仅供参考,但实际的函数duplicateContact()导致了问题 如果有人能帮我指出我的错误,我希望能够使用这个函数,而不让它杀死其他一切 //add more contacts document.getElementById('C_addContact'

我有一个函数,它可以中断页面上所有其他javascript/jquery

我试图用下面的函数做的是在按下按钮时复制一个div,并将其附加到初始div之后(可以复制到按下的次数),它工作得很好,除了其他所有操作都会中断

我在上面添加了代码片段仅供参考,但实际的函数
duplicateContact()
导致了问题

如果有人能帮我指出我的错误,我希望能够使用这个函数,而不让它杀死其他一切

//add more contacts
document.getElementById('C_addContact').onclick = duplicateContact;


var i = 0;
var original = document.getElementById('C_contacts');
var nextElement = $.extend(original);

function duplicateContact()
{
    var clone = original.cloneNode(true); // "deep" clone
    clone.id = "C_contacts" + ++i; // there can only be one element with an ID

    nextElement.parentNode.insertBefore(clone, nextElement.nextSibling);

}
以下是我剩余的js:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<script type="text/javascript">
//show hidden div upon select box selection
$(function() {
    $('#otherTitleField').hide(); 
    $('#title').change(function(){
        if($('#title').val() == 'Other') {
            $('#otherTitleField').show(); 
        } else {
            $('#otherTitleField').hide(); 
        } 
    });
});


//show hidden div upon radio button selection
$(document).ready(function() {
   $('input[type="radio"]').click(function() {
       if($(this).attr('id') == 'postno') {
            $('#postalnofield').show(); 
       }        
       else {
            $('#postalnofield').hide();   
       }
   });
});

//show different hidden div based on checkboxes
function valueChanged1()
{
    if($('#tfn').is(":checked")) {
        $("#tfnfield").show();
    }
    else
        $("#tfnfield").hide();
}

function valueChanged2()
{
    if($('#abn').is(":checked")) {
        $("#abnfield").show();
    }
    else
        $("#abnfield").hide();
}

//clear contacts div
function clearBox(elementID)
{
    if(elementID != 'C_contacts') {
        document.getElementById(elementID).innerHTML = "";
    }

}
</script>

//选择“选择框”时显示隐藏的div
$(函数(){
$(“#其他标题字段”).hide();
$('#title')。更改(函数(){
如果($('#title').val()=='其他'){
$(“#其他标题字段”).show();
}否则{
$(“#其他标题字段”).hide();
} 
});
});
//选择单选按钮时显示隐藏的div
$(文档).ready(函数(){
$('input[type=“radio”]”)。单击(函数(){
if($(this.attr('id')=='postno'){
$(“#postalnofield”).show();
}        
否则{
$(“#postalnofield”).hide();
}
});
});
//根据复选框显示不同的隐藏div
函数值changed1()
{
如果($('#tfn')。为(“:选中”)){
$(“#tfnfield”).show();
}
其他的
$(“#tfnfield”).hide();
}
函数值changed2()
{
如果($('abn')是(“:选中”)){
$(“#abnfield”).show();
}
其他的
$(“#abnfield”).hide();
}
//清除通讯录组
函数clearBox(elementID)
{
如果(elementID!=“C_联系人”){
document.getElementById(elementID).innerHTML=“”;
}
}
以及正在克隆的div的HTML:

<div id="C_contacts">
    <p><label for="C_familyName">Family name<span class="mandatory">*</span></label>
    <input type="text" id="C_familyName" name="Section C Family Name" required></p>

    <p><span style="display:inline-block; width:49%;">
    <label for="C_givenName">First given name<span class="mandatory">*</span></label>
    <input type="text" id="C_givenName" name="Section C Given Name" required></span>

    <span style="display:inline-block; width:49%;">
    <label for="C_otherName">Other given name/s<span class="mandatory">*</span></label>
    <input type="text" id="C_otherName" name="Section C Other Names" required>
    </span></p>

    <p><label for="C_position">Position held<span class="mandatory">*</span></label>
    <input type="text" id="C_position" name="Section C Position Held" required></p>

    <p><span style="display:inline-block; width:49%;">
    <label for="C_busPhone">Business phone<span class="mandatory">*</span></label>
    <input type="tel" id="C_busPhone" name="Section C Business Phone" required>
    </span>

    <span style="display:inline-block; width:49%;">
    <label for="C_mobPhone">Mobile phone</label>
    <input type="tel" id="C_mobPhone" name="Section C Mobile">
    </span></p>

    <p><label for="C_busEmail">Business email address</label>
    <input type="email" id="C_busEmail" name="Section C Email"></p>

    <p><label for="C_thisApp C_busOp">This person is the authorised contact for information about:<span class="mandatory">*</span></label><br>
    <input type="checkbox" id="C_thisApp" name="This Application" value="thisApp"> this application<br>
    <input type="checkbox" id="C_busOp" name="Operation of Business" value="busOp"> the operation of the business after we have granted a licence</p>

    <p><input type="button" id="C_removeContact" value="Remove contact" onclick="clearBox(this.parentNode.parentNode.id)"></p>
    <p><input type="button" id="C_addContact" onclick="duplicateContact()" value="Add more contacts"></p>

    <hr>
    </div>

姓*

名* 其他给定名称*

职位*

商务电话* 手机

业务电子邮件地址

此人是以下信息的授权联系人:*
此应用程序
在我们授予许可证后的业务运营



更新:显然我有两个版本的jquery,这导致了问题。我不知道我怎么会错过这个-谢谢大家的建议和帮助,这已经解决了。

我不知道你的实际代码是什么,但我可以看到每次你克隆一个div,其中你正在克隆
删除和添加按钮。但是您需要为克隆创建一个
添加按钮
,并且所有克隆div都有删除按钮。另外,新生成的div不会调用函数
clearBox
,为了使其工作,您可以使用和使用show-hide来显示代码,从而缩短代码。下面是可以帮助您实现功能的工作代码段

//添加更多联系人
document.getElementById('C_addContact')。onclick=duplicateContact;
var i=0;
var original=document.getElementById('C_contacts');
var nextElement=$.extend(原始);
函数复制联系人(){
var clone=original.cloneNode(true);/“deep”clone
clone.id=“C_contacts”+++i;//只能有一个id为的元素
nextElement.parentNode.insertBefore(克隆,nextElement.nextSibling);
}
//选择“选择框”时显示隐藏的div
$(函数(){
$(“#其他标题字段”).hide();
$('#title')。更改(函数(){
$('#otherTitleField')。切换(this.value=='Other');
});
//选择单选按钮时显示隐藏的div
$('input[type=“radio”]”)。单击(函数(){
$('#postalnofield')。切换(this.id=='postno');
});
//将事件委派与文档一起使用以删除动态div
$(文档)。在('单击','上。删除联系人',函数(){
$(this).最近的('.c-contacts').attr('id')!=='c\u contacts'&&
$(this).closest('.c-contacts').remove();
});
});
//根据复选框显示不同的隐藏div
函数值changed1(){
$(“#tfnfield”).toggle($(“#tfn”).is(“:checked”);
}
函数值changed2(){
$(“#abnfield”).toggle($(“#abn”).is(“:checked”);
}


姓*

名* 其他给定名称*

职位*

商务电话* 手机

业务电子邮件地址

此人是以下信息的授权联系人:*
此应用程序
在我们授予许可证后的业务运营



您是否也可以共享html?其他元素如
otherTitleField
是否在克隆元素中?console中是否显示任何错误。这有什么问题?至少我认为您为两个元素分配了相同的I'd,因为您也更改了nextElement的ID。谢谢您-是的,我知道我复制了“添加更多联系人”按钮,但在使用单个按钮时遇到了问题:(您的工作片段对此很有帮助!