开发者

jquery append choking on quotes in ei

This jQuery statement works in recent versions of Firefox and Chrome but throws an error in IE 8.

left_bar_string = "<tr><td><a href='#' onclick= "return newPopU开发者_JS百科pWindow('somelink','window', '1000','800','100','0','yes')">Directions</a></td></tr>";

$("#side_bar").append(left_bar_string);

I think problem is with double quotes. Any comments/solutions?


This is a good example of why you should use DOM manipulation rather than innerHTML for this kind of thing:

var tr = $("<tr>");
var td = $("<td>").appendTo(tr);
$("<a>").text("Directions").attr("href", "#")
  .attr("onclick", "return newPopUpWindow('somelink','window', '1000','800','100','0','yes')")
  .appendTo(td);
$("#side_bar").append(tr);

Basically everything will be correctly escaped for you.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜