Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
251 views
in Technique[技术] by (71.8m points)

javascript - how to pass ID value onclick function from anchor tag by click on image using MVC?

Based on the database value status will be Y or N. If it Y means it will active.png will be displayed. it is working fine. when i click active.png image then anchor tag onclick="GetRecords1(' + item.ModuleID + '); Function the ID value is not passed to the event.

How to pass the active.png image click the ID value.

<script>
    $(document).ready(function () {
        $("#DomainID").change(function () {
            var id = $(this).val();
            $("#example tbody tr").remove();
            $.ajax({
                type: 'POST',
                url: '@Url.Action("ViewModules")',
                dataType: 'json',
                data: { id: id },
                success: function (data) {
                    var items = '';
                    $.each(data.EmpList, function (i, item) {
                        $("#findValue").show();
                        /*Find Role here - Comparing Emp List ModuleId to RoleList ModuleId*/
                        var RoleName = $(data.role).filter(function (index, item) {
                            return item.ModuleID == item.ModuleID
                        });

                        if (item.ParentModuleID == -1) {
                            item.ModuleName = " -- " + item.ModuleName
                        } else {
                            item.ModuleName = item.ModuleName
                        }
                        var Status = '';
                        if (item.Status == "Y") {
                            Status = '<a href="JavaScript:void(0)" onclick="GetRecords1(' + item.ModuleID + ');" title="Disable status"><img src="/img/Active.png" height="22" width="42"/></a>'
                        } else {
                            Status = '<a href="JavaScript:void(0)" id="inActiveStatus" title="Active status"><img src="/img/InActive.png" height="22" width="42"/></a>'
                        }

                        var rows = "<tr>"
                            + "<td>" + (i + 1) + "</td>"
                            + "<td>" + item.ModuleName + "</td>"
                            + "<td>" + item.Url + "</td>"
                            + "<td>" + RoleName[i].RoleName + "</td>"
                            + "<td>" + '<a href="@Url.Action("EditModules", "Account")?id=' + item.ModuleID + '" class="font-icon font-icon-pencil" title="Edit"></a>&nbsp;&nbsp;&nbsp;' + Status + "</td>"
                            + "</tr>";
                        $('#example tbody').append(rows);
                    });
                },
                error: function (ex) {
                    var r = jQuery.parseJSON(response.responseText);
                        alert("Message: " + r.Message);
                        alert("StackTrace: " + r.StackTrace);
                        alert("ExceptionType: " + r.ExceptionType);
                }
            });
            return false;
        });
    });
</script>

Pass:

<script>
    $(document).ready(function () {
        $('#example tbody').on('click', function GetRecords1(ModuleID) {
            var id = ModuleID;
            alert("Status Clicked:" + ModuleID);
        });
    });
</script>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

<a id="123" onclick="someFunction(this.id)"></a>

javascript code:-

someFunction(id){
??console.log(id)
}


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...