jQuery到Javascript的转换。帮我这样做我知道jquery比javascript更有优势。但是这个想用Javascript做。 [英] jQuery to Javascript conversion. Help me to do this. I know jquery has more advantages than javascript. But this one want to do with Javascript.
本文介绍了jQuery到Javascript的转换。帮我这样做我知道jquery比javascript更有优势。但是这个想用Javascript做。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
function resetTabs(){
$( #content> div)。hide(); // 隐藏所有内容
$( #tabs a)。attr( id, ); // 重置ID
}
var myUrl = window 。 location .href; // 获取网址
var myUrlTab = myUrl.substring(myUrl.indexOf( #)); // 对于mywebsite.com/tabs.html#tab2,myUrlTab =#tab2
< span class =code-keyword> var myUrlTabName = myUrlTab.substring( 0 , 4 ); // 对于上面的示例,myUrlTabName = #tab
( function (){
$( #content> ; div)。hide(); // 最初隐藏所有内容
$( #tabs li:first a)。attr( id, 当前); // 激活第一个标签
$( #content> div:first)。fadeIn(); // 显示第一个标签内容
$( < span class =code-st ring>#tabs a)。on( click, function (e){
e.preventDefault();
if ($( this )。attr( id)== 当前){ // 检测当前标签
return
}
else {
resetTabs();
$( this )。attr( id, current); // 激活此
$($(这个)。attr(' name'))。fadeIn(); // 显示当前标签的内容
}
});
for (i = 1 ; i< = $( #tabs li)。length; i ++){
if (myUrlTab == myUrlTabName + i){
resetTabs();
$( a [name =' + myUrlTab + '])。attr( id, current); // 激活网址标签
$(myUrlTab).fadeIn(); // 显示网址标签内容
}
}
}) ()
解决方案
( #content> div)。hide(); // 隐藏所有内容
( #tabs a)。attr( id, ); // 重置ID
}
var myUrl = window 。 location .href; // 获取网址
var myUrlTab = myUrl.substring(myUrl.indexOf( #)); // 对于mywebsite.com/tabs.html#tab2,myUrlTab =#tab2
< span class =code-keyword> var myUrlTabName = myUrlTab.substring( 0 , 4 ); // 对于上面的示例,myUrlTabName = #tab
( function (){
( #content> div)。hide(); // 最初隐藏所有内容< /跨度>
function resetTabs(){
$("#content > div").hide(); //Hide all content
$("#tabs a").attr("id",""); //Reset id's
}
var myUrl = window.location.href; //get URL
var myUrlTab = myUrl.substring(myUrl.indexOf("#")); // For mywebsite.com/tabs.html#tab2, myUrlTab = #tab2
var myUrlTabName = myUrlTab.substring(0,4); // For the above example, myUrlTabName = #tab
(function(){
$("#content > div").hide(); // Initially hide all content
$("#tabs li:first a").attr("id","current"); // Activate first tab
$("#content > div:first").fadeIn(); // Show first tab content
$("#tabs a").on("click",function(e) {
e.preventDefault();
if ($(this).attr("id") == "current"){ //detection for current tab
return
}
else{
resetTabs();
$(this).attr("id","current"); // Activate this
$($(this).attr('name')).fadeIn(); // Show content for current tab
}
});
for (i = 1; i <= $("#tabs li").length; i++) {
if (myUrlTab == myUrlTabName + i) {
resetTabs();
$("a[name='"+myUrlTab+"']").attr("id","current"); // Activate url tab
$(myUrlTab).fadeIn(); // Show url tab content
}
}
})()
解决方案
("#content > div").hide(); //Hide all content
("#tabs a").attr("id",""); //Reset id's } var myUrl = window.location.href; //get URL var myUrlTab = myUrl.substring(myUrl.indexOf("#")); // For mywebsite.com/tabs.html#tab2, myUrlTab = #tab2 var myUrlTabName = myUrlTab.substring(0,4); // For the above example, myUrlTabName = #tab (function(){
("#content > div").hide(); // Initially hide all content
这篇关于jQuery到Javascript的转换。帮我这样做我知道jquery比javascript更有优势。但是这个想用Javascript做。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文