Loading javascript in a Dojo ContentPane
I am stuck again. I am trying to load some javascript (a number spinner) into a Dojo content pane. And I get a nice ugley message:
Message: HTML Parsing Error: Unable to modify the parent container element before the child element is closed (KB927917)
Here is my code. Any ideas?
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/dojo/1.4.0/dojo/dojo.xd.js" djConfig="isDebug: false, parseOnLoad: true"></script>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/dojo/1.4/dijit/themes/tu开发者_StackOverflow中文版ndra/tundra.css" />
<link rel="stylesheet" href="numberspinner.css" type="text/css" media="screen" />
<script type="text/javascript" src="numberspinner.js"></script>
<script type="text/javascript">
var init = function()
{ dojo.require('dijit.layout.ContentPane');
}
dojo.addOnLoad(init);
</script>
</head>
<body class="tundra">
<div id="notworkingtab" dojoType="dijit.layout.ContentPane" title="Location">
<script type="text/javascript">
var abc= new SpinControl();
abc.SetMaxValue(5);
abc.SetMinValue(0);
abc.SetCurrentValue(0);
abc.SetIncrement(0.5);
document.body.appendChild(abc.GetContainer());
abc.StartListening();
</script>
</div></div>
</body>
</html>
And if anyone cares, I got my numberspinner from here: http://www.switchonthecode.com/tutorials/javascript-controls-the-spin-control
It shows me the number spinner, but not the content pane, and I get the error above... If I take the number spinner out the content pane works ok. Or if I take the contentpane out, the number spinner works ok.
Thanks gggggggg
I think that the dojox.layout.ContentPane
widget is what you are looking for.
dojox.layout.ContentPane
is an extension to dijit.layout.ContentPane
providing script execution, among other things.
I guess the comment/answer I have for you is are you trying to do this "non" dojo like. Basically by doing the things you are doing, you will end up with a very un-dojo like application.
If the native dijit or dojox controls don't provide the functionality you want, you would be better off wrapping your number spinner as a dijit Widget yourself. You get a lot of advantages, like the dijit.layout.ContentPane
"owning" the sub control and will automatically manage it, etc. At first I thought creating custom Widgets would be daunting, but in the end, it isn't difficult at all.
Also, dijit.layout.ContentPane
doesn't normally allow the running of JavaScript on load, since the parser ignores it. You can use the dojox.layout.ContentPane
to provide this functionality, but over time I have learned that usually what I want to do can be done via a <script type="dojo/method">
or <script type="dojo/connect">
.
Personally I think you will be much happier with the results long term.
For anyone interested I got it.. Blond moment.
document.getElementById("myDiv").appendChild(starrating.GetContainer());
精彩评论