为什么我的jquery切换不起作用

时间:2016-08-18 12:08:45

标签: jquery html angularjs

这就是为什么我的切换不起作用

<script>
    $(document).ready(function () {
        $("#tab").hide()
        $("#btn1").click(function () {
            $("#tab").toggle();
        }) 
     })       
</script>

Html代码

<div>
    <table>
        <tr>
            <th>
                <b>Employee Name</b>
            </th>
        </tr>
        <tr ng-repeat="Emp in John">
            <td>
                <input type="button" id="btn1" value="click" />
                {{Emp.Name}}
                <table id="tab">
                    <tr>
                        <th>
                            <b>OrderId</b>
                        </th>
                    </tr>
                    <tr ng-repeat="Joy in Emp.order">
                        <td>
                            {{Joy.OrderId}}

                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</div>

2 个答案:

答案 0 :(得分:0)

相反,您应该使用ng-click并为您的每个元素提供唯一ID,如下所示。

<div>
    <table>
        <tr>
            <th>
                <b>Employee Name</b>
            </th>
        </tr>
        <tr ng-repeat="Emp in John track by $index">
            <td>
                <input type="button" id="btn1{{$index}}" value="click"  ng-click="toggel($index)"/>
                {{Emp.Name}}
                <table id="tab{{$index}}">
                    <tr>
                        <th>
                            <b>OrderId</b>
                        </th>
                    </tr>
                    <tr ng-repeat="Joy in Emp.order">
                        <td>
                            {{Joy.OrderId}}

                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</div>

你可以编写角度js函数来执行切换效果。就像下面一样

$scope.toggel = function(index){
$("#tab"+index).toggle();

}

答案 1 :(得分:0)

你忘记了几个分号。可能是为什么。

public ActionResult Compare(int id)
    {
        ViewData["SampleID"] = id;

        return View();
    }

    [HttpPost]
    public ActionResult Compare(int id, HttpPostedFileBase uploadFile)
    {
        Sample model = _db.Sample_Read(id);
        System.IO.Stream modelStream = null;
        float result = 0;

        _db.Sample_Stream(model.FileId, out modelStream);

        ImgProc.ProcessImage.Similarity(modelStream, uploadFile.InputStream,
                out result);

        ViewData["SampleID"] = id;
        ViewData["match"] = result;

        return View();
    }