开发者

Javascript/Jquery quote and double quotes escaping

A simple jquery line of code:

if ($j('#page2').length) {
    $j('#myPlaceHolder2').html('<button class=\"b开发者_JAVA技巧utton3\" type=\"button\">Page II</button>');
}

This works perfectly fine. When I later create a span with id myPlaceHolder2, it displays the button.

Now I need to add an onclick event

 onclick=\"javascript:  $j('#'+openc).fadeOut('normal', function(){$j('#page2').fadeIn('slow')});openc='page2';\"

To the above .html, as follows

   $j('#myPlaceHolder2').html('<button class=\"button3\" type=\"button\" onclick=\"javascript:  $j('#'+openc).fadeOut('normal', function(){$j('#page2').fadeIn('slow')});openc='page2';\">Page II</button>');

And all hell breaks loose. I tried escaping each ' with \ but it breaks my site entirely for some reason. I'm not very familiar with javascript or jquery, only learning as I go, so any indication as to how to get this done would be helfpul, thank you!


Add it with jQuery:

$j('#myPlaceHolder2')
    .html('<button class=\"button3\" type=\"button\">Page II</button>')
    .find('.button3')
    .click(function () {
        $j('#'+openc).fadeOut('normal', function(){$j('#page2').fadeIn('slow')});openc='page2';
    });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜