English 中文(简体)
Display印法
原标题:Displaying Source Of Javascript Code

我想做的是:

<html>
  <head>
    <script id="ViewSource" src="someJSfile.js"/>
    <script language="javascript">
      function View() {
        var el=document.getElementById("ViewSource"); //works
        var ta=document.getElementById("ta");         //works
        ta.value=el.innerHTML;                        //doesn t work
      }
    </script>
  </head>
  <body>
    <textarea id="ta"/>
    <a href="javascript:View();">View Javascript Source Code</a>
  </body>
</html>
// (please pardon any typos/errors, the above is just to illustrate what I mean)

当然,“内部超文本”在文字标签上不做工作。 我能看到什么财产/财产?

我认识到这一点非常容易地在浏览器中点击电源。 我的cra希望能够用 j子做吗?

提前感谢。

问题回答

Why don t you just fire an AJAX call and download the "someJSFile.js"? Once you downloaded it you would have access to it in a JS variable.

如果你使用jQuery,可以轻易使用$.get:

Edit:从理论上来说,它甚至连重载档案,因为档案存放在浏览器上(取决于你的服务器环境和浏览器环境)。

  • Christian

为此:

  function View() {
    var el=document.getElementById("ViewSource"); //works
    var ta=document.getElementById("ta");         //works
    ta.value=el.text;                             //works!
  }

如果你设定了ta.inner/60/8 = el.inner/60/8,至少会有机会工作。


<a href="http://www.google.com">bleah
<script id="thescript" type="text/javascript">
var links = document.getElementsByTagName( a );
for (var i = 0; i < links.length; i++) {
 if (links[i].href == "http://www.google.com/") links[i].href = "http://www.blather.blorg/"
}
</script>
<br clear="all" />
<textarea id="view">
</textarea>
<script type="text/javascript">
document.getElementById("view").innerHTML =
 document.getElementById("thescript").innerHTML;
</script>

上述工作似乎可行,但我需要扩大案文的范围,以观察所有内容。





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

热门标签