简体   繁体   English

如何使用Jquery从锚标记中查找ID

[英]How To Find Id From Anchor Tag Using Jquery

Here i am trying to find the taskid present in anchor tag using Jquery on click of that anchor tag having class=POtskComment. 在这里,我试图通过单击具有class = POtskComment的锚标记来使用Jquery查找锚标记中存在的taskid。
But as i click the anchor tag taskid id is undefined. 但是,当我单击锚标记taskid id是未定义的。
Any help will be heartly thankful.Thank You 任何帮助将由衷的感谢。谢谢

Below is my Html 以下是我的HTML

 @foreach (var item1 in Model)
                    {
                        <tbody>
                            <tr>
                                <td>
                                    <a class="POtskComment" taskid="@item1.TaskId" tskassinid="@item1.TskAssId" tskname="@item1.TaskName">
                                        @Html.DisplayFor(modelItem => item1.TaskName)
                                    </a>
                                </td>
                            </tr>
                        </tbody>
                    }


Below Is Jquery 下面是jQuery

<script>
$(document).ready(function (event) {
    $(".POtskComment").click(function (event) {

        var paramTaskId3 = $(this).closest("tr").find("td").attr("tskid");

        var parameter = { taskId: paramTaskId };
        $.ajax({
            url: "/TaskAssignedDailyLogs/_POIndex",
            type: "get",
            dataType: "html",
            data: parameter,
            success: function (data)
            {
                $("#reportResult").html(data);
            }
        });

    });
});
</script>

Try this 尝试这个

var paramTaskId3 = $(this).attr("taskid");

the attribute is also misspelled 该属性也拼写错误

错别字:应该是'taskid'而不是'tskid',因为您的attr是在anchor标签上,而不是td标签上,因此请使用$(this).attr('taskid');

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

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