实现功能:在一个容器里点击一个链接,在另外一个容器中显示这个链接所指向页面的内容。
<html>
<head>
<script src="./dojo/dojo.js">
</script>
<script>
dojo.require("dojo.widget.ContentPane");
var links = null, display = null;
dojo.addOnLoad(init);
function init(){
links = dojo.widget.byId("links");
display = dojo.widget.byId("display");
// listen to links domNode for onclick event
// lowercased on all DOM events as opposed to widget events
//"onclick",必须是小写的
dojo.event.connect(links.domNode, "onclick", 'relayClicks');
}
// finds out if this is a link event
function relayClicks(evt){
var node = evt.target;//取得事件源
if(node.nodeName.toLowerCase() == "a"){
// it is a link, prevent the browser from unloading the page
evt.preventDefault();
// change page in display pane
display.setUrl(node.href);
}
}
</script>
</head>
<body>
<h1>Example on how to easily relay <a href="someurl.html" target="display"> clicks</h1>
<div dojoType="ContentPane"
widgetId="links"
style="float:left ; width: 200px; height: 400px; border: 1px solid red;"
>
<a href="link1.html">Link 1</a><br/>
<a href="link2.html">Link 2</a><br/>
<a href="link3.html">Link 3</a><br/>
</div>
<div dojoType="ContentPane"
widgetId="display" name="display" id ="display"
style="width: 600px; height: 400px; border: 1px solid blue;"
></div>
</body>
</html>
<html>
<head>
<script src="./dojo/dojo.js">
</script>
<script>
dojo.require("dojo.widget.ContentPane");
var links = null, display = null;
dojo.addOnLoad(init);
function init(){
links = dojo.widget.byId("links");
display = dojo.widget.byId("display");
// listen to links domNode for onclick event
// lowercased on all DOM events as opposed to widget events
//"onclick",必须是小写的
dojo.event.connect(links.domNode, "onclick", 'relayClicks');
}
// finds out if this is a link event
function relayClicks(evt){
var node = evt.target;//取得事件源
if(node.nodeName.toLowerCase() == "a"){
// it is a link, prevent the browser from unloading the page
evt.preventDefault();
// change page in display pane
display.setUrl(node.href);
}
}
</script>
</head>
<body>
<h1>Example on how to easily relay <a href="someurl.html" target="display"> clicks</h1>
<div dojoType="ContentPane"
widgetId="links"
style="float:left ; width: 200px; height: 400px; border: 1px solid red;"
>
<a href="link1.html">Link 1</a><br/>
<a href="link2.html">Link 2</a><br/>
<a href="link3.html">Link 3</a><br/>
</div>
<div dojoType="ContentPane"
widgetId="display" name="display" id ="display"
style="width: 600px; height: 400px; border: 1px solid blue;"
></div>
</body>
</html>