【问题标题】:how to write onclick event for href tag如何为 href 标签编写 onclick 事件
【发布时间】:2012-05-31 15:27:09
【问题描述】:

谁能帮我在href标签上的onClick事件上写这个?

 string x= "<a href=\"JavaScript:callfunction(event,'"+ y.id.tostring() + "');\">click</a>";

【问题讨论】:

  • 你想做什么?它在做什么?你有什么问题?

标签: javascript jquery asp.net asp.net-mvc asp.net-mvc-2


【解决方案1】:
string x = string.Format(
    "<a href=\"#\" onclick=\"callfunction(event, '{0}')\">click</a>", 
    y.id
);

【讨论】:

    【解决方案2】:

    为什么不这样:

    string x= "<a href=\"#\" onclick=\"callfunction(event,'"+ y.id.tostring() + "');\">click</a>";
    

    【讨论】:

      【解决方案3】:

      只是一种使用 DOM 负责方法来完成此类任务的替代方法

      var x     = document.createElement('a');
      x.href    = "#";
      x.onclick = function(evt) {
         callfunction(evt, y.id.tostring())
      }
      
      <destination-node>.appendChild(x);
      

      【讨论】:

        猜你喜欢
        • 2011-04-02
        • 2019-09-10
        • 2011-02-13
        • 1970-01-01
        • 1970-01-01
        • 2018-01-10
        • 1970-01-01
        • 2012-06-10
        • 1970-01-01
        相关资源
        最近更新 更多