开发者

javascript missing ) argument

I'm getting this error with this javascript can anyone help me figure out what i'm doing wrong?

$(this).prepend('<a class="booknow2 sidelink sidelinkNew" href="javascript:__doPostBack('SetSess','')"><img src="../../imag开发者_开发百科es1/button/leftEdge.png" width="4" height="35" style="float:left; margin:0; padding:0;" alt="book now" /><img src="../../images1/button/rightEdge.png" width="4" height="35" style="float:right; margin:0; padding:0;" alt="book now" /><span>Check availability &raquo;</span></a>');

It's giving me the error

missing ) after argument list

Can anyone help?

Thanks

Jamie


It looks like you need to escape some single quotes in there:

... __doPostBack(\'SetSess\',\'\') ...


You need to escape enclosed quotes like this:

__doPostBack(\'SetSess\',\'\')


Just for your information, but there is a better syntax then to prepend the whole thing as a huge HTML fragment. You can construct the whole thing with jQuery from scratch:

var anchor = $('<a>', {
    'class': 'booknow2 sidelink sidelinkNew', 
    // Try to use event handlers instead - inline event handlers are *bad*
    href: "javascript:__doPostBack('SetSess','')"
}).prependTo(this); 

$('<img>', {
    'width': '4',
    'height': '35',
    'alt': 'book now',
    'src': '../../images1/button/rightEdge.png'
}).css({
    // Try to use CSS instead - add a class 
    // and define the CSS in a separate stylesheet
    'float': 'left',
    'margin': 0,
    'padding': 0,
}).appendTo(anchor);

$('<span>', {
    html: 'Check availability &raquo;'
}).appendTo(anchor);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜