Two onClick actions one button

前端 未结 4 1250
北海茫月
北海茫月 2020-12-01 14:48

Does someone know a wizards trick to make it work ?



        
相关标签:
4条回答
  • 2020-12-01 15:00
    <input type="button" value="..." onClick="fbLikeDump(); WriteCookie();" />
    
    0 讨论(0)
  • 2020-12-01 15:10

    Additional attributes (in this case, the second onClick) will be ignored. So, instead of onclick calling both fbLikeDump(); and WriteCookie();, it will only call fbLikeDump();. To fix, simply define a single onclick attribute and call both functions within it:

    <input type="button" value="Don't show this again! " onclick="fbLikeDump();WriteCookie();" />
    
    0 讨论(0)
  • 2020-12-01 15:12

    Try it:

    <input type="button" value="Dont show this again! " onClick="fbLikeDump();WriteCookie();" />
    

    Or also

    <script>
    function clickEvent(){
        fbLikeDump();
        WriteCookie();
    }
    </script>
    <input type="button" value="Dont show this again! " onClick="clickEvent();" />
    
    0 讨论(0)
  • 2020-12-01 15:12

    Give your button an id something like this:

    
    <input id="mybutton" type="button" value="Dont show this again! " />
    

    Then use jquery (to make this unobtrusive) and attach click action like so:

    
    $(document).ready(function (){
        $('#mybutton').click(function (){
           fbLikeDump();
           WriteCookie();
        });
    });
    

    (this part should be in your .js file too)

    I should have mentioned that you will need the jquery libraries on your page, so right before your closing body tag add these:

    
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script type="text/javascript" src="http://PATHTOYOURJSFILE"></script>
    

    The reason to add just before body closing tag is for performance of perceived page loading times

    0 讨论(0)
提交回复
热议问题