<script>
$("ul#sol_menu li a").addClass(function()) {
var current_page = document.location.href;
if ($(this).attr.("href").match(current_page)) {
$(this).addClass('highlight');
};
});
</script>
Run Code Online (Sandbox Code Playgroud)
这有什么问题?
我使用自定义格式化程序从json填充新网格,格式化程序已定义:
testFormatter(value,el,opts)
{
if (value==0)
{
$(el).addClass("Fail");
}
…
}
Run Code Online (Sandbox Code Playgroud)
我期望单元格使用css类,但如果我检查单元格,则不添加该类.
var section = $('.section');
var width = section.width();
if (width < 960)
section.addClass('.section-slim');
Run Code Online (Sandbox Code Playgroud)
有人能看出这有什么问题吗?我没有得到增加的课程.
当用户单击所选类更改为单击的项时,我试图更改列表项.我有这个代码:
$(function() {
$("a.product-page li").click(function(){
$(this).parent("a").addClass("selected-page");
$("#options a.selected-page").removeClass("selected-page");
});
});
Run Code Online (Sandbox Code Playgroud)
但是,removeClass可以工作,但addClass却没有.
这是网站.
HTML:
<ul id="options">
<a href="#summary" id="summary" class="product-page selected-page"><span></span><li>Summary</li></a>
<a href="#specs" id="specs" class="product-page"><span></span><li>Specs</li></a>
<a href="#media" id="media" class="product-page"><span></span><li>Media</li></a>
<a href="#reviews" id="review" class="product-page"><span></span><li>Reviews</li></a>
</ul>
Run Code Online (Sandbox Code Playgroud)
CSS:
ul#options {
margin-left:0px;
}
ul#options li{
list-style:none;
padding: 10px 20px;
background: #CCC;
border-top: 1px #999 solid;
border-left: 1px #999 solid;
border-right: 1px #999 solid;
}
ul#options a{
display:block;
border:none !important;
}
ul#options a.selected-page span{
position:absolute;
width:0px;
height:0px;
border-width:10px;
border-color:transparent #999999 transparent transparent;
border-style:solid;
margin-left:270px; …Run Code Online (Sandbox Code Playgroud) 这是jQuery:
$(document).ready(function() {
$('#box').click(function() {
$(this).addClass('fullColor');
});
});
Run Code Online (Sandbox Code Playgroud)
这是CSS:
#box {
width:200px;
height:200px;
background-color:blue;
opacity:0.5;
}
.fullColor {
opacity:1.0;
}
Run Code Online (Sandbox Code Playgroud)
JSFiddle:http://jsfiddle.net/VPW6c/
我的html页面中有一堆div,它们都是块元素(一个在另一个上面,没有浮动),我想要的是每次这些div中的一个从窗口顶部达到150px时,它得到一个类.active应用于它.所有这些div都具有相同的类名,但它们各自具有不同的ID以区分它们.所以我需要一些jQuery代码,可以对每个div执行相同的过程,而不必为每个div编写代码.
这是html:
<div id="steps">
<div class="step" id="step-1"></div>
<div class="step" id="step-2"></div>
<div class="step" id="step-3"></div>
<div class="step" id="step-4"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
我有jquery工作,但它针对一个ID,所以我需要它更动态,以便它可以针对每个.总共只有4个步骤.
var distance = $('#step-1').offset().top - 150,
$window = $(window);
$window.scroll(function() {
if ( $window.scrollTop() >= distance ) {
$('#step-1').addClass('active');
}
});
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助!
我正在学习JQuery,在编写自己的小脚本时遇到了问题.所以我有一个导航栏,每按一次按钮,它应该将其css类从'btn'切换到'activebtn'.出于测试目的,我希望能够单击SAME按钮,并将其切换回来,尽管这不会发生.JQuery不会更新类吗?如果是这种情况,我将如何强制JQuery这样做?
<div class="btn">Hello</div>
<div class="btn">World</div>
<script>
$( ".btn" ).click(function() {
$(this).removeClass('btn');
$(this).addClass('activebtn');
});
$( ".activebtn" ).click(function() {
$(this).removeClass('activebtn');
$(this).addClass('btn');
});
</script>
Run Code Online (Sandbox Code Playgroud) This functions starts when I click on a link. It needs to remove all '.is-active' classes on the elements with the attribute [data-route]. And add the class '.is-active' on the [data-route] element that is connected with the link I clicked on.
toggle: function(section){
var sections = document.querySelectorAll('[data-route]');
for (i = 0; i < sections.length; i++){
document.querySelector('[data-route]').classList.remove('is-active');
}
document.querySelector(section).classList.add('is-active');
}
Run Code Online (Sandbox Code Playgroud)
But this doesn't work. It doesn't remove the classes?
See example: http://jordypouw.github.io/myFED2/deeltoets1/index.html
P.S. it has to be in vanilla JavaScript.
我的html设置如下:
<div class="containerElement">
<div class="element"></div>
</div>
<div class="containerElement">
<div class="element"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
每当点击".element"时,我想在元素的".containerElement"中添加一个类,并且只添加一个"containerElement"实例.
如果点击一个元素,我如何在javascript中向一个"containerElement"实例添加一个类,到目前为止,我的jquery代码是:
$('.element').click(function(){
$('.containerElement', this).addClass('highlighted');
})
Run Code Online (Sandbox Code Playgroud)
什么是正确的语法而不是"$('.containerElement',this)"
addclass ×10
jquery ×9
javascript ×4
html ×3
css ×2
removeclass ×2
class ×1
hover ×1
jqgrid ×1
scroll ×1
toggleclass ×1
width ×1