简体   繁体   中英

Javascript click function not working

I'm trying to write a simple javascript function that will clone some html input fields when the user clicks a button, but for some reason the button's click function isn't being called when I click it. Any ideas why?

Here's the javascript:

<SCRIPT LANGUAGE="JavaScript">
$(document).ready(
    function(){

        $("#default-label").hide();
        $("#default-element").hide();

        var counter = parseInt($("#counter").val());

        $("#addProduct").click(
            function(){

                var product = $('#fieldset-default');
                var newProduct = product.clone(true);
                newProduct.insertAfter(product);
                    document.getElementById("addProduct").innerHTML = 'Add More';
                    $("#counter").val(++counter);
            }
         );
    }
);
</script>

My HTML for the button:

<button id="addProduct" type="button" name="add">Add Product</button>

我认为你错过了jquery插件,包括最新版本的jquery库,如果不存在的话。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM