【问题标题】:jQuery trigger click on aspx page is not workingjQuery触发点击aspx页面不起作用
【发布时间】:2012-01-20 15:22:14
【问题描述】:

我的 ASPX 标记如下

<a id="lnkLogin" href="javascript:__doPostBack('ctl00$LoginReg1$lnkLogin','')">Login</a>

我的功能如下

function LogOut() {
        $("#lnkLogin").trigger('click');
    }

由于某种原因,此触发点击不起作用?

我也尝试过像这样从后面的代码中做到这一点

If Request.UrlReferrer IsNot Nothing AndAlso Request.UrlReferrer.AbsoluteUri.Contains("32088") Then

        ' Define the name and type of the client script on the page. 
        Dim csName As [String] = "ButtonClickScript"
        Dim csType As Type = Me.[GetType]()

        ' Get a ClientScriptManager reference from the Page class. 
        Dim cs As ClientScriptManager = Page.ClientScript

        ' Check to see if the client script is already registered. 
        If Not cs.IsClientScriptBlockRegistered(csType, csName) Then
            Dim csText As New StringBuilder()
            csText.Append("<script type=""text/javascript""> function LogOut() {")
            csText.Append("$('#lnkLogin').trigger('click');} </")
            csText.Append("script>")
            cs.RegisterClientScriptBlock(csType, csName, csText.ToString())
        End If
    End If

但不使用

【问题讨论】:

  • 你为什么不直接做 $('#lnkLogin).click(function(){ doPostBack('ctl00$LoginReg1$lnkLogin',''); return false; });跨度>
  • @Evan 没用(它不会触发并触发点击链接)

标签: jquery vb.net triggers clientscriptmanager


【解决方案1】:

试试这个

function LogOut() {
    $("#lnkLogin")[0].click();
}

【讨论】:

  • 这给了我错误“Uncaught TypeError: Object javascript:__doPostBack('ctl00$LoginReg1$lnkLogin','') has no method 'click'”
  • 如何生成该链接?你在用LinkButton控件吗?
猜你喜欢
  • 2011-08-17
  • 1970-01-01
  • 1970-01-01
  • 2016-01-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多