简体   繁体   English

在外部JS文件中编辑vars

[英]edit vars in an extern JS File

I have a html file and a JS file. 我有一个html文件和一个JS文件。 In the JS file are vars: JS文件中有vars:

(function (lib, img, cjs) {

var p; // shortcut to reference prototypes

// library properties:
lib.properties = {
    width: 300,
    height: 250,
    fps: 30,
    color: "#FFFFFF",
    manifest: [
        {src:"images/logo_bg.png", id:"logo_bg"}
    ]
};
....

Now, you see the source path of an image. 现在,您将看到图像的源路径。 -> images/logo_bg.png -> images / logo_bg.png

How do I change the path in my html file? 如何更改html文件中的路径?

<head>
<script src="test.js"></script>

<script>
var canvas, stage, exportRoot;
function init() {
    canvas = document.getElementById("canvas");
    images = images||{};

    var loader = new createjs.LoadQueue(false);
    loader.addEventListener("fileload", handleFileLoad);
    loader.addEventListener("complete", handleComplete);
    loader.loadManifest(lib.properties.manifest);
}
function handleFileLoad(evt) {
    if (evt.item.type == "image") { images[evt.item.id] = evt.result; }
}
function handleComplete() {
    exportRoot = new lib.test();

    stage = new createjs.Stage(canvas);
    stage.addChild(exportRoot);
    stage.update();

    createjs.Ticker.setFPS(lib.properties.fps);
    createjs.Ticker.addEventListener("tick", stage);
}
</script>
</head>

<body onload="init();" style="background-color:#D4D4D4">
    <canvas id="canvas" width="300" height="250" style="background-color:#FFFFFF"></canvas>
</body>

The idea to handle it with "getElementById" doesn't work yet... 用“ getElementById”处理它的想法还行不通...

Thank you very much! 非常感谢你!

via DOM manipulation. 通过DOM操作。

$('#yourImage').attr("src", "your/new/path");

or without jQuery: 或没有jQuery:

document.getElementById("yourImage").setAttribute("src", "your/new/path");

http://www.w3schools.com/jsref/met_element_setattribute.asp http://www.w3schools.com/jsref/met_element_setattribute.asp

http://api.jquery.com/attr/ http://api.jquery.com/attr/

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

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