Javascript jQueryUI-手风琴-设置a href中的ID
首先,感谢您在本网站上提供的所有信息。它极大地帮助我找到问题的答案。这是我在这里的第一篇帖子,希望有人能给我指引正确的方向 我目前正在一个网站上工作,并试图建立一个相当大的手风琴设置(30+手风琴)。我一直在寻找答案,找到了能提供大量信息的答案,以及我想要实现的目标 ID是根据Javascript jQueryUI-手风琴-设置a href中的ID,javascript,jquery,html,jquery-ui,Javascript,Jquery,Html,Jquery Ui,首先,感谢您在本网站上提供的所有信息。它极大地帮助我找到问题的答案。这是我在这里的第一篇帖子,希望有人能给我指引正确的方向 我目前正在一个网站上工作,并试图建立一个相当大的手风琴设置(30+手风琴)。我一直在寻找答案,找到了能提供大量信息的答案,以及我想要实现的目标 ID是根据标记中显示的文本设置的。当我从数据库中提取事件的缩写和描述时,我有一个相当长的。(示例:AAM-服装和配件营销系列)。我可以让这个工作,但ID会像“aam_u-u服装”…等等 我需要能够将ID创建为a href=“#myN
标记中显示的文本设置的。当我从数据库中提取事件的缩写和描述时,我有一个相当长的。(示例:AAM-服装和配件营销系列)。我可以让这个工作,但ID会像“aam_u-u服装”…等等
我需要能够将ID创建为a href=“#myNameHere”中的#后面的任何内容,该名称仅为缩写。(缩写和说明需要在h3中显示)
内容
如果您将“Link1”更改为“Link1Test”,则会将ID更改为“Link1Test”
$(函数(){
var$accordion=$(“#accordion”).accordion({active:false,collapsable:true}),
hashId=0;
if(window.location.hash){
$accordion.儿童('h3')。每个(功能(i){
var txt=$(this.text().toLowerCase().replace(/\s+/g,“”);
this.id=txt;
if(txt==window.location.hash.slice(1)){
hashId=i;
}
});
$accordion.手风琴({
活动:hashId,
动画:对,
高度样式:“内容”,
可折叠的:是的,
创建:函数(事件、用户界面){
$accordion.儿童('h3')。每个(功能(i){
$(本)。在('')之前;
});
$accordion.find('.accordion链接')。单击(函数(){
$accordion.accordion(“选项”、“活动”和$(this.data('index'));
});
}
});
}
});
感谢您提供的帮助和帮助,非常感谢您的时间和知识。锚定的href
属性是从标题的id
属性设置的;这些id
s是通过第一次调用中的txt
变量设置的。因此,这就是我们要编辑的内容,我们可以使用预设分隔符来提取前几个字符:
var DELIMITER = '_-_';
$accordion.children('h3').each(function(i){
var txt = $(this).text().toLowerCase().replace(/\s+/g,'_');
txt = txt.slice(0, txt.indexOf(DELIMITER)); // <- extracts Abbreviation
this.id = txt;
if (txt === window.location.hash.slice(1)) {
hashId = i;
}
});
在描述中可以有多个分隔符的实例,因为.indexOf
和regex匹配都将返回第一个实例。由于这是在实际用于任何地方之前编辑txt
值,因此它应该与代码的其余部分兼容非常感谢,这正是我想要的。
$(function() {
var $accordion = $("#accordion").accordion({active: false, collapsible: true}),
hashId = 0;
if (window.location.hash) {
$accordion.children('h3').each(function(i){
var txt = $(this).text().toLowerCase().replace(/\s+/g,'_');
this.id = txt;
if (txt === window.location.hash.slice(1)) {
hashId = i;
}
});
$accordion.accordion({
active: hashId,
animate: true,
heightStyle: 'content',
collapsible: true,
create: function( event, ui ) {
$accordion.children('h3').each(function(i){
$(this).before('<a class="accordion-link link" data-index="' + i + '" href="#' + this.id + '"></a>');
});
$accordion.find('.accordion-link').click(function(){
$accordion.accordion( "option", "active", $(this).data('index') );
});
}
});
}
});
var DELIMITER = '_-_';
$accordion.children('h3').each(function(i){
var txt = $(this).text().toLowerCase().replace(/\s+/g,'_');
txt = txt.slice(0, txt.indexOf(DELIMITER)); // <- extracts Abbreviation
this.id = txt;
if (txt === window.location.hash.slice(1)) {
hashId = i;
}
});
var DELIMITERS = ["_-_", "_:_"]; // <- backslash-escape special characters here
// and then...
txt = txt.replace(new RegExp("(" + DELIMITERS.join("|")) + ").*"), "");
内容
如果您将“Link1”更改为“Link1Test”,则会将ID更改为“Link1Test”
$(函数(){
var$accordion=$(“#accordion”).accordion({active:false,collapsable:true}),
hashId=0;
if(window.location.hash){
$accordion.儿童('h3')。每个(功能(i){
var txt=$(this.text().toLowerCase().replace(/\s+/g,“”);
this.id=txt;
if(txt==window.location.hash.slice(1)){
hashId=i;
}
});
$accordion.手风琴({
活动:hashId,
动画:对,
高度样式:“内容”,
可折叠的:是的,
创建:函数(事件、用户界面){
$accordion.儿童('h3')。每个(功能(i){
$(本)。在('')之前;
});
$accordion.find('.accordion链接')。单击(函数(){
$accordion.accordion(“选项”、“活动”和$(this.data('index'));
});
}
});
}
});
感谢您提供的帮助和帮助,非常感谢您的时间和知识。锚定的
href
属性是从标题的id
属性设置的;这些id
s是通过第一次调用中的txt
变量设置的。因此,这就是我们要编辑的内容,我们可以使用预设分隔符来提取前几个字符:
var DELIMITER = '_-_';
$accordion.children('h3').each(function(i){
var txt = $(this).text().toLowerCase().replace(/\s+/g,'_');
txt = txt.slice(0, txt.indexOf(DELIMITER)); // <- extracts Abbreviation
this.id = txt;
if (txt === window.location.hash.slice(1)) {
hashId = i;
}
});
在描述中可以有多个分隔符的实例,因为.indexOf
和regex匹配都将返回第一个实例。由于这是在实际用于任何地方之前编辑txt
值,因此它应该与代码的其余部分兼容非常感谢,这正是我想要的。
$(function() {
var $accordion = $("#accordion").accordion({active: false, collapsible: true}),
hashId = 0;
if (window.location.hash) {
$accordion.children('h3').each(function(i){
var txt = $(this).text().toLowerCase().replace(/\s+/g,'_');
this.id = txt;
if (txt === window.location.hash.slice(1)) {
hashId = i;
}
});
$accordion.accordion({
active: hashId,
animate: true,
heightStyle: 'content',
collapsible: true,
create: function( event, ui ) {
$accordion.children('h3').each(function(i){
$(this).before('<a class="accordion-link link" data-index="' + i + '" href="#' + this.id + '"></a>');
});
$accordion.find('.accordion-link').click(function(){
$accordion.accordion( "option", "active", $(this).data('index') );
});
}
});
}
});
var DELIMITER = '_-_';
$accordion.children('h3').each(function(i){
var txt = $(this).text().toLowerCase().replace(/\s+/g,'_');
txt = txt.slice(0, txt.indexOf(DELIMITER)); // <- extracts Abbreviation
this.id = txt;
if (txt === window.location.hash.slice(1)) {
hashId = i;
}
});
var DELIMITERS = ["_-_", "_:_"]; // <- backslash-escape special characters here
// and then...
txt = txt.replace(new RegExp("(" + DELIMITERS.join("|")) + ").*"), "");