如何将变量传递给javascript文件<script src =“../js / myfilename.js”> </script>

时间:2013-12-13 00:11:33

标签: javascript parameter-passing

如何将变量传递给javascript文件?

以下是我在页面上对我的js文件的调用:

<script src="../js/myfilename.js"></script>

以下是我想传递给javascript文件的值:

language_value_xxx = "uk";

这是修剪过的javascript文件(myfilename.js):

(function (language_value_xxx) {
....
language: language_value_xxx,
....

1 个答案:

答案 0 :(得分:3)

1

<script> language_value_xxx = "uk"; </script>
<script src="../js/myfilename.js"></script>

2

<script data-lang='uk' src="../js/myfilename.js"></script>

// filename.js
var lang = []
    .slice
    .call(document.querySelectorAll('script'))
    .pop()
    .dataset
    .lang
    ;

无论如何,这种方法根本不是一个好习惯。