简体   繁体   中英

Javascript Passing parameters to root $(function () {..}) into .js

i have a .js file and i want to pass the parameters to use in the file root of the file

$(function () {

    var defaults = {
      usernameFlag: false,
      passwordFlag: false
     };

    var options;

    var getFlags = {
        parameters: function(args) {
            options = $.extend({}, defaults, args);     
            console.log(options);       
            }
    };
    console.log(options);
});

this is my body content

<script type="text/javascript">
  getFlags.parameters({ usernameFlag: true, passwordFlag: false});
</script>

In practice, I want to pass values ​​from the body to a js file and initialize options with the sent values

只需将函数导出到全局对象即可:

window.getFlags = ...

您只需通过在开始脚本标记中添加src='/path/to/your/script.js'即可完成此操作。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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