javascript – 迭代jquery对象返回字符串而不是dom元素

我有以下循环:

for(var myScreen in wizardScreens){
    if(step==index)$(myScreen).show();
    else $(myScreen).hide();
    index++;
}

wizardScreens定义为$(“.wizardScreen”,wizard);,其中wizard是一个DOM元素.在循环中,myScreen设置为字符串,而不是DOM元素.任何人都可以解释为什么会这样吗?

解决方法:

jQuery集合已经有了内置的迭代函数

wizardscreens.each(function (index, screen) {
  if (index == step)
    $(screen).show();
  else
    $(screen).hide();
}

或者甚至可能更适合您的使用:

var activescreen = wizardscreens.eq(step);
activescreen.show();
wizardscreens.not( activescreen[0] ).hide();

这完全避免了显式迭代.

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: <span id=&quot...
jQuery 添加水印 <script src="../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...