简体   繁体   English

谁能帮我解决gregjacobs / Autolinker.js的工作示例

[英]Can anyone help me with working examples of gregjacobs/Autolinker.js

I am trying to make a text links on a page active hyperlinks. 我正在尝试使页面上的文本链接成为活动超链接。 Every time new text links are added to the page via the form, I need the atolink script to rerun so newly added text links are also made active hyperlinks without reloading the entire page. 每次通过表单将新的文本链接添加到页面时,我都需要重新运行atolink脚本,因此新添加的文本链接也将成为活动的超链接,而无需重新加载整个页面。

This is the form 这是表格

Try placing the script before the body tag ends. 尝试将脚本放置在body标签结束之前。 The problem is script is executing before the tag is even rendered. 问题在于脚本甚至在呈现标记之前就已执行。 Something like this should help. 这样的事情应该有所帮助。

<html>
  <head></head>
  <body>
    <div id="testing">
      http://www.test.com
      <br> @test
      <br> #test
      <br>
    </div>
    <script src="./dist/Autolinker.js"></script> <------ Also place the library at the end 

    <script type="text/javascript"> 
      var myTextEl = document.getElementById('testing');
      myTextEl.innerHTML = Autolinker.link(myTextEl.innerHTML);
    </script>
  </body>
</html>

Thats because document.getElementById( 'testing' ) is returning null .. and you are trying to get innerHTML of null object.. 那是因为document.getElementById( 'testing' )返回null ..并且您试图获取null对象的innerHTML

It is returning null because your script is loaded before <div id="testing"> . 它返回null,因为您的脚本在<div id="testing">之前加载。 Move the script below it and it will work.. 将脚本移到其下方,它将起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM