English 中文(简体)
如何在动态创造的干 to中通过 Java字功能
原标题:How to pass a Javascript function in a dynamically created div

我想像我在下文尝试的那样,把 j字功能传给一个充满活力的 d。 如果我用普通的文字来取代该作品的描述,那么在创建Text Node时,是否有通过联合材料的方法?

    newDiv = document.createElement("div");
    newContent = document.createTextNode("<script type="text/javascript">var pager = new Pager(3); pager.init(); pager.showPageNav( pager ,  pageNavPosition ); pager.showPage(1); </script>");
    newDiv.appendChild(newContent);

TIA

问题回答

A <script> tag is not a text node.
You need to create a <script> element using document.createElement.

However, you should not do this, unless you re trying to load an external script file dynamically (eg, JSONP)

var js=document.createElement( script );
  js.setAttribute("type","text/javascript");
  js.appendChild(document.createTextNode(" var pager = new Pager(3); pager.init(); pager.showPageNav( pager ,  pageNavPosition ); pager.showPage(1); "));
  var newDiv=document.createElement("div");
  newDiv.appendChild(js);
  document.appendChild(newDiv);




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签