How do I escape a string inside JavaScript code inside an onClick handler?

前端 未结 13 948
半阙折子戏
半阙折子戏 2020-11-28 03:44

Maybe I\'m just thinking about this too hard, but I\'m having a problem figuring out what escaping to use on a string in some JavaScript code inside a link\'s onClick handle

13条回答
  •  长情又很酷
    2020-11-28 04:30

    Try avoid using string-literals in your HTML and use JavaScript to bind JavaScript events.

    Also, avoid 'href=#' unless you really know what you're doing. It breaks so much usability for compulsive middleclickers (tab opener).

    Select
    

    My JavaScript library of choice just happens to be jQuery:

    
    

    If you happen to be rendering a list of links like that, you may want to do this:

    Bar
    Baz
    
    
    

提交回复
热议问题