Tag: removeclass

如何使用jQuery或JavaScript基于当前URL和单击事件将一个类“active”分配给li元素

我正在尝试创建一个菜单,只要选择并加载了一个类“active”就会被分配给该页面。 现在它默认仅应用于索引页面。 我的菜单片段: Main News Contacts

removeclass不起作用

我有一个非常简单的问题,实际上这不是问题,这是修复javascript错误,无论如何,这里是代码: $(document).ready(function() { $(‘#accordion a.item’).click(function () { $(this).addClass(‘selected’); $(this).removeClass(‘selected’); $(‘#accordion li’).children(‘ul’).slideUp(‘slow’); $(this).siblings(‘ul’).slideDown(‘slow’); }); }); 和HTML: BANKS BLA BLA BLA PETROL BLA BLA BLA 当我单击其中一个链接时,会将“选定”类添加到其中,但是当我单击其他链接时,“选定”类不会删除,那可能是什么错误? 谢谢大家的帮助! 对此,我真的非常感激!

jQuery在两个以上的类之间切换

我已经在这里发布了一个关于jQuery toggle方法的问题但是问题是即使使用migrate插件它也行不通。 我想写一个将在五个类之间切换的脚本(0 – > 1 – > 2 – > 3 – > 4 – > 5)。 这是我使用的JS代码的一部分: $(‘div.priority#priority’+id).on(‘click’, function() { $(this).removeClass(‘priority’).addClass(‘priority-low’); }); $(‘div.priority-low#priority’+id).on(‘click’ ,function() { $(this).removeClass(‘priority-low’).addClass(‘priority-medium’); }); $(‘div.priority-medium#priority’+id).on(‘click’, function() { $(this).removeClass(‘priority-medium’).addClass(‘priority-normal’); }); $(‘div.priority-normal#priority’+id).on(‘click’, function() { $(this).removeClass(‘priority-normal’).addClass(‘priority-high’); }); $(‘div.priority-high’+id).on(‘click’, function() { $(this).removeClass(‘priority-high’).addClass(‘priority-emergency’); }); $(‘div.priority-emergency’+id).on(‘click’, function() { $(this).removeClass(‘priority-emergency’).addClass(‘priority-low’); }); 这不是代码的第一个版本 – 我已经尝试过其他一些东西,比如: $(‘div.priority#priority’+id).toggle(function() { $(this).attr(‘class’, […]

单击时用jquery替换img src

这可能看起来像是儿童游戏,但我无法弄清楚如何替换图像的src属性。 src是生成图像的“build.php”。 我想要的是当我点击“混合”它将运行build.php生成一个新图像,删除旧图像并显示一个漂亮的淡出/淡出的新图像。 还有一个“建立新图像”,它在新图像加载时隐藏。 我试过了 $(“#mix”).click(function(){ var img = new Image(); $(img).load(function () { $(this).hide(); $(‘#loader’).removeClass(‘loading’).append(this); $(this).fadeIn(); }).attr(‘src’, ‘build.php’); }); 但是第二次点击“混合”时,它会在旧图像下面放置新图像,而不是删除旧图像。

jQuery Event-Handler只需单击一下即可更改CSS-Class

我使用jQuery的Click-Function有一些奇怪的行为。 我也尝试使用on-EventHandler。 Twitter的Bootstrap Navbar有一些简单的标记,我正在尝试更改li-tag的CSS-Class。 在这种情况下,我想删除活动的CSS类,并将其添加到当前单击的li-tag。 但是,只需点击一下即可应用更改。 因此当例如’Preview’是当前的可视活动元素并且我点击’Document’时,CSS-Class似乎不会改变。 当我在’Slidecast’上点击之后,视觉活动元素是’Document’,这不是预期的行为。 下一步点击’预览’,现在’幻灯片’是视觉活动元素。 我做错了什么? 我尝试使用remove和add以及toggleClass,但这并不重要。 这是我的代码和标记。 JS被包含在Dom-Ready-Function中。 Document Slidecast Preview Notes Questions Activities JS $(“#document_navbar a”).on(‘click’, function(e) { // Hide all content, display the one related to hash-tag $(“.document_view”).toggle(false); $(app_locationToId($(this).attr(“href”))).toggle(true); // Here is the part that does not work: //$(“#document_navbar li.active”).removeClass(“active”); //$(“a[href='” + window.location.hash + “‘]”).parent().addClass(‘active’); // Another try […]

在Sencha ExtJS框架中应该删除哪些组件事件? (恼人的红线)

当使用它的分割条(组件的上边缘)调整此组件的大小时,这条恼人的红线会随机出现。 我确实通过删除它的CSS类来弄清楚如何永久地删除红线,但是有一个问题22.我很难在Sencha ExtJS框架中删除这个Activity1组件的CSS类。 我有一个样式问题,其中backgroundColor样式属性显示该组件内容器的非常特定布局的红线。 红色实际上来自名为“.x-border-layout-ct”的类。 由于这三个组件的backgroundColor是’#F1F1F1’(white-ish),并且由于这三个组件位于Activity1之上,因此它应该掩盖Activity1 backgroundColor。 事实上它确实存在,但只有当我将Activity1面板(在视口中)调整为特定大小时。 我能够通过使用“this.removeCls(’。x-border-layout-ct’)”删除此类来纠正问题,但如果我应用“this.callParent(arguments)”,则它无法正常工作。 在这种情况下,CSS类会回来。 避免使用“this.callParent(arguments)”并不好,因为面板标题不会被渲染。 Ext.define(‘App.view.module1.Activity1’, { extend: ‘Ext.form.Panel’, xtype: ‘view-module1-activity1’, title: ‘test’, layout: { type: ‘border’ }, items: [{ id: ‘top_component’, region: ‘north’, xtype: ‘component’, html: ‘top panel’, style: { backgroundColor: ‘#F1F1F1’ } }, { id: ‘middle_component’, region: ‘center’, xtype: ‘component’, html: ‘Middle Component’, height: 50, style: { […]

addClass()然后单击removeClass()(jquery)

我想做一些画廊。 想要使用addClass来显示图像,然后点击同一个地方删除这个新类我用谷歌搜索求助,但是在试图让它正常工作一小时之后,我就是在寻求帮助。 我在这里找到了反向选项的解决方案(首先删除并添加) 码: #window { width: 570px; height: 455px; position: relative; background-color: grey; padding: 20px; margin: 0 auto; top: 50%; margin-top: -225px; } .image { display: inline-block; margin: 5px; } #wrapper { width: 568px; height: 455px; position: absolute; } .close { display: none; } .big_image{ width: 100%; display: block; } $(document).ready(function(){ $(‘.image’).nailthumb({containerClass:’image’,height:100, width:100, fitDirection:’center’, […]

removeClass函数无法正常工作

我编写的函数允许用户通过单击选择和取消选择div。 现在,我试图做的是一个function,一旦按下a ,取消选择一切,但它只取消选择我的一些 div。 这是代码: var divs = document.getElementsByClassName(‘fuori’); for(i = 0, j = divs.length; i < j; i++){ divs[i].addEventListener('click', function(){ if(!hasClass(this, 'selected')){ this.className = this.className + " selected"; } else { removeClass(this, 'selected'); } }); } removeClass函数就是这个 function removeClass(ele,cls) { if (hasClass(ele,cls)) { var reg = new RegExp(‘(\\s|^)’+cls+'(\\s|$)’); ele.className=ele.className.replace(reg,’ ‘); } } 这是deselectAll function […]

添加/删除类onclick与JavaScript没有图书馆

我正在开发一个移动网站,并希望使用JS只是添加和删除类。 因此,为了保持良好和轻松,我不想使用jQuery。 我有以下HTML: Brand Menu Home Benefits Features Case Studies In-Store Contact Us Close Menu 以及到目前为止的以下JS: window.onLoad = init; function init() { document.getElementById(‘openPrimaryNav’).onClick = openPrimaryNav(); document.getElementById(‘closePrimaryNav’).onClick = closePrimaryNav(); } function openPrimaryNav() { document.getElementById(‘primaryNav’).className = ‘open’; } function closePrimaryNav() { document.getElementById(‘primaryNav’).className = ”; } 我不能让这个工作有人能告诉我我做错了什么吗? 提前谢谢了。 基于下面提供的答案的正确JS: window.onload = init; function init() { document.getElementById(‘openPrimaryNav’).onclick = openPrimaryNav; […]

CSS3 – 添加类以触发动画并在完成时删除类

我有一个div,当我点击它时,jquery添加了一个启动动画运行的类。 当动画停止时(3秒后),我希望删除该类,这样当再次单击div时,动画将重新开始。 这只是测试,目前只有Chrome浏览器。 这是我的CSS3: .spin360 { -webkit-animation-name: spin; -webkit-animation-duration: 3s; -webkit-animation-iteration-count: 1; -webkit-animation-timing-function: ease; -webkit-animation-fill-mode: forwards; } @-webkit-keyframes spin { 0% { -webkit-transform: rotateX(0); } 100% { -webkit-transform: rotateX(-360deg); } } 这是我的脚本: $(document).ready(function () { $(‘#spinButton’).click(function () { $(‘#shape’).addClass(‘spin360’); }); }); 这是我尝试过的: $(document).ready(function () { $(‘#spinButton’).click(function () { $(‘#shape’).addClass(‘spin360’).on(‘webkitAnimationEnd’, function () { $(‘#shape’).removeClass(‘spin360’); }); }); […]