第二个JQuery代码不起作用

时间:2017-10-15 04:00:37

标签: javascript jquery

我有两个代码,如果添加第一个代码,第二个代码不起作用,我不知道问题出在哪里以及如何修复,以下是在页脚中使用的代码:

代码1:

<script type="text/javascript">
$(document).ready(function () {
    var names = ["input.name","input.first_name","input.last_name","input.email","input.address","input.city","input.state","input.zip","input.phone","input.country"];
    $.each(names,function (index, item) {
        var regex = new RegExp("\\{\\{"+item+"\\}\\}","g");
        var currVal = localStorage.getItem("garlic:"+document.location.host+"*>"+item);
        $("body:contains('{{"+item+"}}')").each(function() {
            var replace_text = (currVal != null) ? currVal : "";
            var replaced = $(this).html().replace(regex, replace_text);
            $(this).html(replaced);
        });
    });
});
</script>

代码2:

<script type="text/javascript">

$(document).ready(function(){
    $('#agreeCheckbox').click(function(){
        $('#tmp_button-70655').toggle();
        $('#disablebtn').toggle();

});


$('#agreeCheckboxtwo').click(function(){
        $('#button-99411-155-131-111').toggle();
        $('#disablebtntwo').toggle();

});
  });
</script>

1 个答案:

答案 0 :(得分:0)

您是否尝试删除其中一个“准备好”?

<script type="text/javascript">
$(document).ready(function () 
{
    var names = ["input.name","input.first_name","input.last_name","input.email","input.address","input.city","input.state","input.zip","input.phone","input.country"];
    $.each(names, function (index, item) 
    {
        var regex = new RegExp("\\{\\{"+item+"\\}\\}","g");
        var currVal = localStorage.getItem("garlic:"+document.location.host+"*>"+item);
        $("body:contains('{{"+item+"}}')").each(function() 
        {
            var replace_text = (currVal != null) ? currVal : "";
            var replaced = $(this).html().replace(regex, replace_text);
            $(this).html(replaced);
        });
    });

    $('#agreeCheckbox').click(function()
    {
        $('#tmp_button-70655').toggle();
        $('#disablebtn').toggle();

    });

    $('#agreeCheckboxtwo').click(function()
    {
            $('#button-99411-155-131-111').toggle();
            $('#disablebtntwo').toggle();
    });
});