Javascript Symfony2 Jquery什么都不做

Javascript Symfony2 Jquery什么都不做,javascript,jquery,symfony,twig,Javascript,Jquery,Symfony,Twig,所以我用jQuery做了一个简单的函数来检查它是否工作。我不知道为什么会这样,因为我做了我在其他堆栈问题上发现的所有事情。它只是不起任何作用 我现在所做的一切: 1) 我创建了脚本并将其保存在一个文件中: $('.plus').on('click', function (e) { $this = $(this); alert("product id "+$this.parent('.item').find('input').data('id') + " Quantity "+$t

所以我用jQuery做了一个简单的函数来检查它是否工作。我不知道为什么会这样,因为我做了我在其他堆栈问题上发现的所有事情。它只是不起任何作用

我现在所做的一切:

1) 我创建了脚本并将其保存在一个文件中:

$('.plus').on('click', function (e) {
    $this = $(this);
    alert("product id "+$this.parent('.item').find('input').data('id') + " Quantity "+$this.parent('.item').find('input').val())
});
2) 我在twig中添加了代码以使脚本正常工作:

<div class="item">
    <input type="text" value="2" data-id="1" />
    <a href="javascript:void(0)" class="plus">+</a>
    <a href="javascript:void(0)">-</a>
</div>
<div class="item">
    <input type="text" value="2" data-id="2" />
    <a href="javascript:void(0)" class="plus">+</a>
    <a href="javascript:void(0)">-</a>
</div>
<div class="item">
    <input type="text" value="2" data-id="3" />
    <a href="javascript:void(0)" class="plus">+</a>
    <a href="javascript:void(0)">-</a>
</div>
4) 我做断言:转储:

php app/console assetic:dump
5) 我在我的config.yml中添加了捆绑包,因为我收到错误:
您必须将“”添加到assetic.bundle配置中

assetic:
    debug:          "%kernel.debug%"
    use_controller: false
    bundles:        [ MpShopBundle ]

这就是我所做的,但代码仍然不起作用。dump命令没有给我任何表示路由正确的错误。但是脚本不起作用…

您需要将javascript代码包装到jQuery的
ready
事件中

$(document).ready(function () {
    $('.plus').on('click', function (e) {
        $this = $(this);
        alert("product id " + $this.parent('.item').find('input').data('id') + " Quantity " + $this.parent('.item').find('input').val())
    });
});

好啊2015年迄今为止最愚蠢的错误。。。非常感谢。
assetic:
    debug:          "%kernel.debug%"
    use_controller: false
    bundles:        [ MpShopBundle ]
$(document).ready(function () {
    $('.plus').on('click', function (e) {
        $this = $(this);
        alert("product id " + $this.parent('.item').find('input').data('id') + " Quantity " + $this.parent('.item').find('input').val())
    });
});