2014-10-18 106 views
-6

我刚开始学习jQuery,这是我的第一个项目;我有经典的JavaScript函数,我需要转换为jQuery。任何jQuery专家都可以帮助我吗?将javascript转换为jquery

预先感谢您。

for (var i = 0; (l_link = document.getElementsByTagName("link")[i]); i++) { 
    if (l_link.getAttribute("rel")) { 
    if (l_link.getAttribute("rel").indexOf("style") != -1 && l_link.getAttribute("title")) { 
     l_link.disabled = true; 
     if (l_link.getAttribute("title") == theme_id) { 
     l_link.disabled = false; 
     applied = false; 
     activetheme = v_css; 
     } 
    } 
    } 
} 
+2

这将是很高兴看到你最好的尝试。否则就像*“请为我做吧!”*你不觉得吗? – 2014-10-18 09:19:21

+1

“*其中[我]需要转换为[jQuery] *” - 为什么? – 2014-10-18 09:22:57

+0

伙计们...我学习这就是为什么我问这样的基本问题...因为你的投票,我不能再问任何问题..你可以请你还原你的投票......这样我可以学习一些基本的东西这里...我只是在这里学习...请大家...谢谢你。 – SmartDev 2014-10-18 12:02:43

回答

1
$('link').each(function(i, link) { 
    link = $(link); 
    if (link.attr('rel') && link.attr('rel').indexOf("style") != -1 && link.attr('title')) { 
     if (link.attr('title') == theme_id) { 
      link.attr('disabled', false); 
      applied = false; 
      activetheme = v_css; 
     } else { 
      link.attr('disabled', true); 
     } 
    } 
}); 
0

它看起来像这样在JQuery中。

$('link').each(function(i, l_link) { 
      if (l_link.attr('rel') && l_link.attr('rel').indexOf("style") != -1 && l_link.attr('title')) { 
     if (l_link.attr('title') == theme_id) { 
      l_link.attr('disabled', false); 
      applied = false; 
      activetheme = v_css;  
     } else { 
      l_link.attr('disabled', true); 
     } 
    } 
});