English 中文(简体)
在“补充”内添加“超”字眼,减少 escaping问题
原标题:Add HTML inside Element reduce problems with escaping
  • 时间:2011-11-23 23:25:54
  •  标签:
  • javascript

I m trying to add HTML inside an element but I m having serious problems escaping quotes and such.

我曾尝试过这么多的事情,我甚至不听说过的话,这就是它是如何看待的:(我消除了任何穿梭的企图,因为它使它更加混淆了)。

document.getElementById("sharerContainer").innerHTML =
    "<div onclick= teleport( justwalk.it/house?uid=" + sharerID +
    " ) ><div class= face  style= background-image: url( https://graph.facebook.com/" +
    sharerFID + "/picture ); ></div>" + sharer;

是否有另一种方式通过javascript书写超文本以减少这类问题?

最佳回答
document.getElementById("sharerContainer").innerHTML =
"<div onclick="teleport( justwalk.it/house?uid=" + sharerID +
" );"><div class="face" style="background-image: url( https://graph.facebook.com/" +
sharerFID + "/picture );"></div>" + sharer;

或你可以尝试 j

问题回答

然后使用OMM的操纵(你选择任何途径):

var container = document.getElementById("sharerContainer");

var div = container.appendChild(document.createElement( div ));
div.onclick = function() {
    teleport("justwalk.it/house?uid=" + encodeURIComponent(sharerID));
};

var inner_div = div.appendChild(document.createElement( div ));
inner_div.style.backgroundImage = "url( https://graph.facebook.com/" + sharerFID + "/picture );";
inner_div.className =  face ;

div.appendChild(document.createTextNode(sharer));

不清楚这些变量的内容是什么,因此,你可能不得不将它 t为你们工作。

Why can t you just do normal DOM manipulation, like so:

var sharerContainer = document.getElementById( sharerContainer );
var myDiv = document.createElement( div );
var subDiv = document.createElement( div );
subDiv.appendChild(document.createTextNode(sharer);
myDiv.appendChild(subDiv);
sharerContainer.appendChild(myDiv);

myDiv.onclick = function() {
    teleport( justwalk.it/house?uid=  + sharerID);
};

?





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签