简体   繁体   English

如何在jquery中使用外部javascript库?

[英]How Should use external javascript library in jquery?

What's wrong in my initialization, when I trying to use external javascript library in jquery and I want to get a custom value from my pages and then manipulate that value by using external javascript plugin and then return back new value(or replace with old value), below is my code: 当我尝试在jquery中使用外部javascript库并且想要从页面中获取自定义值,然后使用外部javascript插件操纵该值,然后返回新值(或替换为旧值)时,初始化有什么问题? ,以下是我的代码:

 <html>
  <head>
  <meta charset="utf-8">
  <script src="jquery.js"></script>
  <script src="external-library.js"></script>
  <script>
  var OldValue;
  var NewValue;
  OldValue = $(".raw-Data").html();
  NewValue = new External-function(OldValue);

  $(document).ready(function() {
  $(".result").text(NewValue);
  });
  </script>
  </head>

  <body>
  <div class="raw-Data">1318781876406</div>
  <div class="result"></div>
  </body>
  </html>

When I add my <script> section in my document <head> section like above code all things works correctly and I haven't any problem, But the problem arise when I want to add <script> section in end of document before closing <body> tag because Drupal CMS initializing javascript library in bottom of document. 当添加我<script>部分我的文档中<head>部分像上面的代码中所有的东西正常工作,我没有任何问题,但出现问题时,我想补充<script>关闭前的文件结尾部分<body>标记,因为Drupal CMS正在初始化文档底部的javascript库。

 <html>
  <head>
  <meta charset="utf-8">
  </head>

  <body>
  <div class="raw-Data">1318781876406</div>
  <div class="result"></div>

  <script src="jquery.js"></script>
  <script src="External-Library.js"></script>
  <script>
  var OldValue;
  var NewValue;

  $(document).ready(function() {
  OldValue = $(".raw-Data").html();
  NewValue = new ExternalFunction(OldValue);
  $(".result").text(NewValue);
  });
  </script>
  </body>
  </html>

I want to know what's the correct and compacted method to do this. 我想知道什么是正确的压缩方法。

Thanks for any help or suggestion. 感谢您的帮助或建议。

JS variable names / function cannot contain - sign. JS变量名称/函数不能包含-符号。

the common naming convention used by javascript is camelCase javascript使用的通用命名约定是camelCase

so that New-Value should become newValue and External-Function should change to externalFunction 这样New-Value应该变成newValueExternal-Function应该变成externalFunction

see javascript variable naming convention on w3schools for more information : 有关更多信息,请参见w3schools上的javascript变量命名约定:

https://www.w3schools.com/js/js_conventions.asp https://www.w3schools.com/js/js_conventions.asp

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

相关问题 如何在打字稿中使用外部javascript库 - Angular 4 - How to use External javascript library in typescript - Angular 4 如何使用外部Javascript库(如jQuery)重命名Google Closure样式表? - How do I use Google Closure Stylesheet renaming with an external Javascript Library such as jQuery? 发布javascript库...我应该如何处理外部依赖关系? - Releasing javascript library… how should I handle the external dependencies? 如何在反应中使用引线(外部 javascript 库)? - How to use leader-line (an external javascript library) in react? 如何在CRM Dynamics中使用外部Javascript库? - How do I use an external Javascript library in CRM Dynamics? 如何在 vaadin 中使用外部 javascript 库? - how can i use an external javascript library in vaadin? 如何在前端外部javascript文件中使用aa库模块? - How to use a a library module in a front-end external javascript file? 如何使用Javascript在函数内部调用外部库的函数? - How to use Javascript to call an external library's function inside of a function? 如何导入外部 JavaScript 库 - How to import external JavaScript library 在 Angular 8 应用程序中使用外部 JavaScript 库 - Use external JavaScript library in Angular 8 application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM