English 中文(简体)
日内瓦
原标题:Firefox/XHTML: creating and appending nodes

I m试图用符合DOM标准的耳光取代在代码中的低超字体。

<html>
    <body>hehe</body>
    <script type="text/javascript">
        var myDiv = document.createElement( div );
        myDiv.setAttribute( id ,  myDivID );
        document.getElementsByTagName( body )[0].appendChild(myDiv);
        var textNode =  <p>This will be dynamically generated.</p> ;
        myDiv.appendChild(textNode);
    </script>
</html>

Sure, The script isn t should be under the body, but if my place it above, the javascript re the mis:

document.getElementsByTagName(“人”)[0] is un Defin

由于尸体还不存在。

但正如现在一样, j子在“儿童”步骤上留下了更远的错误:

uncaught exception:
[Exception... "Could not convert JavaScript argument arg 0 [nsIDOMHTMLDivElement.appendChild]"
nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)"
location: "JS frame :: .....TestStuff/wut.jsp :: <TOP_LEVEL> :: line 8"
data: no]

因此,这里的交易是什么? 可在<条码>myDiv.setAttribute和myDiv.appendChild>>各条码的参考资料和结果相同。

Edit: sorry, the above errors are firefox ones, not chrome ones. The chrome error is: Uncaught Error: NOT_FOUND_ERR: DOM Exception 8 on the myDiv.appendChild line. I don t get why myDiv wouldn t be on the DOM at this point, but chrome doesn t seem to think it is.

Edit2: 因此,这一行文如下:

var textNode =  <p>This will be dynamically generated.</p> ;

加入

var textNode = document.createTextNode( < p>This will be dynamically generated.< /p> );

产出案文将正确无误。 然而,我想知道如何生成和篡改html的chu,该nk将作为实际标记而不是单纯的文字拼写,能够基本上仿效内部的超文本。

问题回答
var textNode =  <p>This will be dynamically generated.</p> ;
myDiv.appendChild(textNode);

您需要创建<代码><p>要素和案文,作为独特的节点。 这应当:

var paragraph = document.createElement( p );
var textNode  = document.createTextNode( This will be dynamically generated. );

paragraph.appendChild(textNode);
myDiv    .appendChild(paragraph);

假设你真的想要<代码><p>...</p>要素。 如果你不能这样做,那么就简单地设定了案文编号,并将之附在myDiv上。

难道你不有理由把你的代码放在“<>上载<>条/条码>上。 它与解决你大多数问题(如果不是全部)一样正确。

现在,你在浏览器完成X射线的垫子之前,重新尝试改造多功能树。





相关问题
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.

热门标签