javascript 函数行为异常
嘿伙计们,我无法让一个功能正常工作,重点是爬过父母,直到我得到一个触发切换动作的人。但是该函数的行为很奇怪,当找到经过验证的标签时,它似乎没有返回 true 并完成递归方式。
unction dock(e){
if(e.get(0).tagName != "BODY"){
alert("current : "+e.get(0).tagName)
e.siblings(".splitter-bar").each(function(){
alert("found sibling : "+$(this).get(0).tagName)
if($(this).length > 0){
e.parent().trigger('toggleDock')
alert("triggered parent : "+e.parent().get(0).tagName)
return true
}
})
if ( dock(e.parent()) ){
alert("validated parent : "+e.parent().get(0).tagName)
return true
}
alert("end dock(), current : "+e.get(0).tagName)
}
return false
}
$(".dockme").live('click', function(event) {
a = dock($(this))
alert("dock returned :"+a)
});
整个代码:
/* when the page is loaded */
$(document).ready(function(){
$("body").splitter({
splitVertical: true,
outline: true,
sizeLeft: 30, minLeft: 0, maxLeft: 100,
resizeToWidth: true,
anchorToWindow: true,
dock: "left",
dockSpeed: 200,
cookie: "docksplitter"
});
$("#a").splitter({
splitHorizontal: true,
outline: true,
sizeBottom: 30, minBottom: 0, maxBottom: 30,
dock: "bottom",
dockSpeed: 200,
cookie: "docksplitter"
});
$("#b").splitter({
splitVertical: true,
sizeRight: 320, minRight: 0, maxRight: 320,
dock: "right",
dockSpeed: 200,
cookie: "docksplitter"
});
function dock(e){
if(e.get(0).tagName != "BODY"){
alert("current : "+e.get(0).tagName)
e.siblings(".splitter-bar").each(function(){
alert("found sibling : "+$(this).get(0).tagName)
if($(this).length > 0){
e.parent().trigger('toggleDock')
alert("triggered parent : "+e.parent().get(0).tagName)
return true
}
})
if ( dock(e.parent()) ){
alert("validated parent : "+e.parent().get(0).tagName)
return true
}
alert("end dock(), current : "+e.get(0).tagName)
}
return false
}
$(".dockme").live('click', function(event) {
a = dock($(this))
alert("dock returned :"+a)
});
});html : http://pastie.org/1329885
hey guys i cant get a function working properly, the point is to climb over the pareents till i get the one to trigger the toggle action. But the function acting weirdly and when the validated tag is found it seems to doesnt returning true and complete the recursive way.
unction dock(e){
if(e.get(0).tagName != "BODY"){
alert("current : "+e.get(0).tagName)
e.siblings(".splitter-bar").each(function(){
alert("found sibling : "+$(this).get(0).tagName)
if($(this).length > 0){
e.parent().trigger('toggleDock')
alert("triggered parent : "+e.parent().get(0).tagName)
return true
}
})
if ( dock(e.parent()) ){
alert("validated parent : "+e.parent().get(0).tagName)
return true
}
alert("end dock(), current : "+e.get(0).tagName)
}
return false
}
$(".dockme").live('click', function(event) {
a = dock($(this))
alert("dock returned :"+a)
});
the whole code :
/* when the page is loaded */
$(document).ready(function(){
$("body").splitter({
splitVertical: true,
outline: true,
sizeLeft: 30, minLeft: 0, maxLeft: 100,
resizeToWidth: true,
anchorToWindow: true,
dock: "left",
dockSpeed: 200,
cookie: "docksplitter"
});
$("#a").splitter({
splitHorizontal: true,
outline: true,
sizeBottom: 30, minBottom: 0, maxBottom: 30,
dock: "bottom",
dockSpeed: 200,
cookie: "docksplitter"
});
$("#b").splitter({
splitVertical: true,
sizeRight: 320, minRight: 0, maxRight: 320,
dock: "right",
dockSpeed: 200,
cookie: "docksplitter"
});
function dock(e){
if(e.get(0).tagName != "BODY"){
alert("current : "+e.get(0).tagName)
e.siblings(".splitter-bar").each(function(){
alert("found sibling : "+$(this).get(0).tagName)
if($(this).length > 0){
e.parent().trigger('toggleDock')
alert("triggered parent : "+e.parent().get(0).tagName)
return true
}
})
if ( dock(e.parent()) ){
alert("validated parent : "+e.parent().get(0).tagName)
return true
}
alert("end dock(), current : "+e.get(0).tagName)
}
return false
}
$(".dockme").live('click', function(event) {
a = dock($(this))
alert("dock returned :"+a)
});
});html : http://pastie.org/1329885
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
e.siblings(...).each
内的函数未从dock
返回true
。所以
我认为你需要这样说:
The function inside
e.siblings(...).each
is not returningtrue
fromdock
.So instead of
I think you need to say something like: