0

i want to do this:

<object type="image/svg+xml" id="tornado5" data="bitmaps/tornado2.svg">
</object>

but i want to do it in javascript dynamically... i tried:

var object2 = document.createElement("object");
object2.type = "image/svg+xml";
object2.data = 'bitmaps/tornado2.svg';
object2.id = "tornado5";
document.getElementById('objLayer').appendChild(object2);  // no .onload method

var ele=document.getElementById("tornado5");
var links = ele.contentDocument.getElementsByClassName('myClass'); //paths in file use
for (var i=0;i<links.length;i++){ links[i].style.fill="#00ff00"; } 

the top html way can call the 3-line-js-color-mod at bottom and it will mod the color of the svg. But if i load the svg the js way, the svg loads, but the color mod wont work. (you can't mod the contentDocument thru an img, only thru an object i'm told).

question 11374059 asks a similar question and he was told to use img. No good here.


C++ Have One Nested Class Inherit From Another Nested Class

I'm writing a cross-platform class hierarchy, and want to keep the platform dependent implementations in their own class (as opposed to having one class with #ifdefs). This is what I have so far, but the compiler is complaining that BaseDef is private. Any help with how I could keep this basic structure while getting it to compile would be greatly appreciated :-)

Edit: It would seem from here that this isn't possible. Any other way I could keep this general structure and still compile?

Root.h

class Root {
    private:
        class BaseDef {
            virtual void foo() = 0;
            virtual void bar() = 0;
        };

        #ifdef _WIN32
        class WinImp;
        #else
        class NixImp;
        #endif

        BaseDef* imp;

        BaseDef* getImp();

    public:
        Root() : imp(getImp()) {}
        void foo();
        void bar();
};

Root.cpp

#include "Root.h"
void Root::foo() {
    imp->foo();
}

void Root::bar() {
    imp->bar();
}

WinImp.h

#ifdef _WIN32
#include "Root.h"
class WinImp : public Root::BaseDef {
    public:
        void foo();
        void bar();
};
#endif

WinImp.cpp

#include "WinImp.h"
#ifdef _WIN32
    Root::WinImp::foo() {

    }

    Root::WinImp::bar() {

    }

    Root::BaseDef* Root::getImp() {
        return new Root::WinImp();
    }
#endif
4

1 に答える 1

1

Object.setAttribute(attr, val); の使用をお勧めします。オブジェクトタグで。すなわち:

var object2 = document.createElement("object");
object2.setAttribute("type", "image/svg+xml");
于 2013-01-25T02:30:25.800 に答える