Javascript HTML/JS:如何显示所选<;李>;内容
我的代码有一些问题。我有两个页面,分别是A页和B页。在B页,有9个主要按钮,每个按钮都有自己的URL。从9个按钮中,有一个按钮将重定向到B页。下面是a页按钮的当前代码,该按钮将重定向到B页 页面A.htmlJavascript HTML/JS:如何显示所选<;李>;内容,javascript,html,jquery,css,Javascript,Html,Jquery,Css,我的代码有一些问题。我有两个页面,分别是A页和B页。在B页,有9个主要按钮,每个按钮都有自己的URL。从9个按钮中,有一个按钮将重定向到B页。下面是a页按钮的当前代码,该按钮将重定向到B页 页面A.html 把你的询盘寄给我们 您可以像下面的代码片段那样添加片段: <div class="main-enquiry"> <div class="inner"> <h1>Send Us Your Enquiry</h1>
把你的询盘寄给我们
您可以像下面的代码片段那样添加片段:
<div class="main-enquiry">
<div class="inner">
<h1>Send Us Your Enquiry</h1>
<div class="marginTop">
<div class="col4 left">
<a href="/community/#section-iconfall-3"></a>
<div class="circleicon">
<a href="/community/#section-iconfall-3"></a>
<a href="/community/#section-iconfall-3"><img src="/App_ClientFile/7ff8cb3f-fbf6-42e7-81da-6db6a0ab2ef4/Assets/i-foundation.png" /></a>
</div>
<h5><a style="color: rgb(0, 0, 0); line-height: 1.2; font-size: 1.1em; font-weight: 600;" href="/community/#section-iconfall-3">TG Foundation</a></h5></div>
</div>
</div>
</div>
这是一个快速解决方法,应该使用location.hash
来实现
更新2:
下面的代码实现使用location.hash
来设置cbpFWTabs
的默认选项卡,我只是添加了一个块来检查选项卡id是否包含在URL哈希中
...
if (idx === undefined) {
this.items.forEach(function (el, i) {
if (el.id === location.hash.substr(1)) {
tabs.current = i;
}
});
}
...
这是完整的文件实现,只需替换它,然后在
中将#section-iconfall-3
附加到href
属性的末尾,这样它就应该链接到community/#section-iconfall-3
/**
* cbpFWTabs.js v1.0.0
* http://www.codrops.com
*
* Licensed under the MIT license.
* http://www.opensource.org/licenses/mit-license.php
*
* Copyright 2014, Codrops
* http://www.codrops.com
*/
(function (window) {
"use strict";
function extend(a, b) {
for (var key in b) {
if (b.hasOwnProperty(key)) {
a[key] = b[key];
}
}
return a;
}
function CBPFWTabs(el, options) {
this.el = el;
this.options = extend({}, this.options);
extend(this.options, options);
this._init();
}
CBPFWTabs.prototype.options = {
start: 0,
};
CBPFWTabs.prototype._init = function () {
// tabs elems
this.tabs = [].slice.call(this.el.querySelectorAll("nav > ul > li"));
// content items
this.items = [].slice.call(
this.el.querySelectorAll(".content-wrap > section")
);
// current index
this.current = -1;
// show current content item
this._show();
// init events
this._initEvents();
};
CBPFWTabs.prototype._initEvents = function () {
var self = this;
this.tabs.forEach(function (tab, idx) {
tab.addEventListener("click", function (ev) {
ev.preventDefault();
self._show(idx);
});
});
};
CBPFWTabs.prototype._show = function (idx) {
let tabs = this;
if (this.current >= 0) {
this.tabs[this.current].className = this.items[this.current].className =
"";
}
// change current
this.current =
idx != undefined
? idx
: this.options.start >= 0 && this.options.start < this.items.length
? this.options.start
: 0;
if (idx === undefined) {
this.items.forEach(function (el, i) {
if (el.id === location.hash.substr(1)) {
tabs.current = i;
}
});
}
this.tabs[this.current].className = "tab-current";
this.items[this.current].className = "content-current";
};
// add to global namespace
window.CBPFWTabs = CBPFWTabs;
})(window);
/**
*cbpFWTabs.js v1.0.0
* http://www.codrops.com
*
*根据麻省理工学院许可证授权。
* http://www.opensource.org/licenses/mit-license.php
*
*版权所有2014,Codrops
* http://www.codrops.com
*/
(功能(窗口){
“严格使用”;
功能扩展(a,b){
for(b中的var键){
如果(b.hasOwnProperty(键)){
a[键]=b[键];
}
}
返回a;
}
功能CBPFWTabs(el,选件){
this.el=el;
this.options=extend({},this.options);
扩展(这个。选项,选项);
这个;
}
CBPFWTabs.prototype.options={
起点:0,
};
CBPFWTabs.prototype.\u init=函数(){
//标签元素
this.tabs=[].slice.call(this.el.queryselectoral(“nav>ul>li”);
//内容项
this.items=[].slice.call(
此.el.querySelectorAll(“.content wrap>section”)
);
//当前索引
这是电流=-1;
//显示当前内容项
这个;
//初始化事件
这个;
};
CBPFWTabs.prototype.\u initEvents=函数(){
var self=这个;
this.tabs.forEach(函数(tab,idx){
tab.addEventListener(“单击”),功能(ev){
ev.preventDefault();
自我展示(idx);
});
});
};
CBPFWTabs.prototype.\u show=函数(idx){
让tabs=这个;
如果(this.current>=0){
this.tabs[this.current].className=this.items[this.current].className=
"";
}
//变流
这是目前的情况=
idx!=未定义
?idx
:this.options.start>=0&&this.options.start
您可以像下面的代码片段那样添加片段:
<div class="main-enquiry">
<div class="inner">
<h1>Send Us Your Enquiry</h1>
<div class="marginTop">
<div class="col4 left">
<a href="/community/#section-iconfall-3"></a>
<div class="circleicon">
<a href="/community/#section-iconfall-3"></a>
<a href="/community/#section-iconfall-3"><img src="/App_ClientFile/7ff8cb3f-fbf6-42e7-81da-6db6a0ab2ef4/Assets/i-foundation.png" /></a>
</div>
<h5><a style="color: rgb(0, 0, 0); line-height: 1.2; font-size: 1.1em; font-weight: 600;" href="/community/#section-iconfall-3">TG Foundation</a></h5></div>
</div>
</div>
</div>
这是一个快速解决方法,应该使用location.hash
来实现
更新2:
下面的代码实现使用location.hash
来设置cbpFWTabs
的默认选项卡,我只是添加了一个块来检查选项卡id是否包含在URL哈希中
...
if (idx === undefined) {
this.items.forEach(function (el, i) {
if (el.id === location.hash.substr(1)) {
tabs.current = i;
}
});
}
...
这是完整的文件实现,只需替换它,然后在
中将#section-iconfall-3
附加到href
属性的末尾,这样它就应该链接到community/#section-iconfall-3
/**
* cbpFWTabs.js v1.0.0
* http://www.codrops.com
*
* Licensed under the MIT license.
* http://www.opensource.org/licenses/mit-license.php
*
* Copyright 2014, Codrops
* http://www.codrops.com
*/
(function (window) {
"use strict";
function extend(a, b) {
for (var key in b) {
if (b.hasOwnProperty(key)) {
a[key] = b[key];
}
}
return a;
}
function CBPFWTabs(el, options) {
this.el = el;
this.options = extend({}, this.options);
extend(this.options, options);
this._init();
}
CBPFWTabs.prototype.options = {
start: 0,
};
CBPFWTabs.prototype._init = function () {
// tabs elems
this.tabs = [].slice.call(this.el.querySelectorAll("nav > ul > li"));
// content items
this.items = [].slice.call(
this.el.querySelectorAll(".content-wrap > section")
);
// current index
this.current = -1;
// show current content item
this._show();
// init events
this._initEvents();
};
CBPFWTabs.prototype._initEvents = function () {
var self = this;
this.tabs.forEach(function (tab, idx) {
tab.addEventListener("click", function (ev) {
ev.preventDefault();
self._show(idx);
});
});
};
CBPFWTabs.prototype._show = function (idx) {
let tabs = this;
if (this.current >= 0) {
this.tabs[this.current].className = this.items[this.current].className =
"";
}
// change current
this.current =
idx != undefined
? idx
: this.options.start >= 0 && this.options.start < this.items.length
? this.options.start
: 0;
if (idx === undefined) {
this.items.forEach(function (el, i) {
if (el.id === location.hash.substr(1)) {
tabs.current = i;
}
});
}
this.tabs[this.current].className = "tab-current";
this.items[this.current].className = "content-current";
};
// add to global namespace
window.CBPFWTabs = CBPFWTabs;
})(window);
/**
*cbpFWTabs.js v1.0.0
* http://www.codrops.com
*
*根据麻省理工学院许可证授权。
* http://www.opensource.org/licenses/mit-license.php
*
*版权所有2014,Codrops
* http://www.codrops.com
*/
(功能(窗口){
“严格使用”;
功能扩展(a,b){
for(b中的var键){
如果(b.hasOwnProperty(键)){
a[键]=b[键];
}
}
返回a;
}
功能CBPFWTabs(el,选件){
this.el=el;
this.options=extend({},this.options);
扩展(这个。选项,选项);
这个;
}
CBPFWTabs.prototype.options={
起点:0,
};
CBPFWTabs.prototype.\u init=函数(){
//标签元素
this.tabs=[].slice.call(this.el.queryselectoral(“nav>ul>li”);
//内容项
this.items=[].slice.call(
此.el.querySelectorAll(“.content wrap>section”)
);
//当前索引
这是电流=-1;
//显示当前内容项
这个;
//初始化事件
这个;
};
CBPFWTabs.prototype.\u initEvents=函数(){
var self=这个;
this.tabs.forEach(函数(tab,idx){
tab.addEventListener(“单击”),功能(ev){
ev.preventDefault();
自我展示(idx);
});
});
};
CBPFWTabs.prototype.\u show=函数(idx){
让tabs=这个;
如果(this.current>=0){
this.tabs[this.current].className=this.items[this.current].className=
"";
}
//变流
这是目前的情况=
idx!=未定义
?idx
:this.options.start>=0&&this.options.start
我认为您应该为页面B添加window.onload事件,在该事件中,您可以将逻辑设置为默认选择第三个选项卡
window.onload = function() {
//your tab selection logic here, put your existing code here which navigates to 3rd tab
}
我认为您应该为页面B添加window.onload事件,您可以在其中