[英]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
应该变成newValue
而External-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.