簡體   English   中英

將另外一個javascript方法綁定到Anchor標記中的href

[英]Bind one more javascript method to the href in Anchor tag

我有一個網頁,其中在onLoad中使用jQuery (外部javascript)創建了錨標記列表 (還在其中定義了href和onclick事件)

例如:

<a href="javascript:method1(1)" onclick="return method2(1);">Test1</a>
<a href="javascript:method1(2)" onclick="return method2(2);">Test2</a>

由於它是通過外部javascript文件創建的,因此我無法編輯此onLoad,方法1的方法定義都不能

現在我想method3 medthod1完成后調用。

任何幫助將不勝感激。

您可以編寫一個包裝函數來同時調用這兩個函數:

<head>
<script>
    function wrapperFunction(arg1, arg2){
        method2(arg1);
        method3(arg2);
    }
</script>
</head>
<body>
<a href="javascript:method1(1)" onclick="wrapperFunction(1,2);">Test1</a>
...

您可以覆蓋method2 ,在外部js創建錨點之后,可以在加載所有資產后使用body標簽的load事件:

function window_load()
{
     var newHandler = method2;
     method2 = function(arg){

         var result = newHandler(arg);

         // ...
         // you can call here any function or something else
         // ...

         return result;
     };
}

我試圖覆蓋method2 ,通過這種方法,您可以更改所需的任何方法

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM