简体   繁体   English

Onclick功能不起作用的HTML

[英]Onclick function not working html

Below is the code that is used in my html.I have written a javascript which works on onclick.whenever i press it javascript is not working.I tried to print alert inside script but the reposnse is not going to the script.This was working earlier,but suddenly its stopprd working.Following is my code: 以下是我的html中使用的代码。我编写了一个可在onclick上运行的javascript。每当我按下javascript都无法正常工作时,我试图在脚本内打印警报,但回购协议无法正常工作。较早,但突然它的stopprd起作用了。以下是我的代码:

<a href="" onclick="add_cart({{product.id}})" title="Add To Cart" class="submit_btn   

add_btn" >+</a>

script: 脚本:

<script type="text/javascript">
    function add_cart()
    {
        alert('hi');
        //checking the attributes valid or not
        var attr_ids=[];
        $('input[type=checkbox]:checked').each(function(){
            attr_ids.push($(this).val());

        });
        var attr_length = attr_ids.length;
        var min_attr = $('#min_attribute').val();
        var max_attr = $('#max_attribute').val();
        if(parseInt(min_attr)<=parseInt(attr_length))
        {
            if(parseInt(attr_length)<=parseInt(max_attr))
            {
                $( "#add_cart_form" ).submit();
            }
            else
            {
                $('#attr_error').html("please select less than"+max_attr +"attributes")
            }

        }
        else
        {
            if(attr_length<min_attr)
            {
                $('#attr_error').html("please select at least"+min_attr +"attributes")
            }
            if(attr_length>max_attr)
            {
                $('#attr_error').html("please select less than"+max_attr +"attributes")
            }
        }

        $( "#add_cart_form" ).submit();

    }

</script>

Please help me with this... 请在这件事上给予我帮助...

尝试以下方法:

<a href="#" onclick="add_cart('{product.id}')" title="Add To Cart" class="submit_btn add_btn" >+</a>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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