如何在javascript函数中获得gridview中我的超链接字段的url

How to get the url of my hyperlink field within a gridview in a javascript function

本文关键字:我的 超链接 字段 url gridview javascript 函数      更新时间:2023-09-26

这是我的超链接代码:

<asp:HyperLink id="UnlinkedUsers"  clientIDMode="static" runat="server"
 onclick ="GetSecurity();"  
 NavigateUrl='<%# string.Format("LinkUsers.aspx?User={0}&Type={1}",
 Eval("Email"), Eval("EntityType")) %>'Text='Link User'>
这是我的JavaScript代码:
<asp:Content ID="ContentPlaceHolderJS" ContentPlaceHolderID="ContentPlaceHolderJS" runat="server">
<script lang="javascript" type="text/javascript">

JS

function GetSecurity() {
    var linkUrl = $(this).attr("href");
    //alert(linkUrl);
    $.ajax({
        type: "POST",
        url: "Dashboard.aspx/CheckSecurity",
        contentType: "application/json; charset=utf-8",
        //data: '{"UserName":"' + userName + '"}',
        data: '{"objectname":"LinkUsers"}',
        //data: '{"objectname":"' + objectname + '"}',
        dataType: "json",
        success: function (data) {
            if (data.d == false)
                alert("You do not have rights to this object.");
            else
                window.location.href = linkUrl.toString();
        }
    });
}

这是不工作。特别是这一行:

var linkUrl = $(this).attr("href");

在浏览器上,我得到错误:

TypeError: a.attributes is undefined

…e.cssText}的,a.setAttribute (b,"+ d);如果(! a.attributes [b],及a.hasAttribute&及! a.hasA…

尝试使用:

this.getAttribute('href')