标签: addclass

选择后向按钮添加类 - jquery

我有一个提交按钮,在用户从选择列表中进行选择之前,该按钮将被禁用。

我想删除禁用属性并添加一个类,以便该按钮成为我在整个站点中使用的标准按钮类(在更改选择列表时)。

我正在尝试以下操作:

$(document).ready(
function(){
    $('#category').change(
        function(){
            if ($(this).val()) {
                $('input:submit').attr('disabled',false);
                $('#btn_show').addClass.attr('button green');

            }
        });

});
Run Code Online (Sandbox Code Playgroud)

#category 是下拉 id,#btn_show 是按钮 id

禁用已删除,但未添加类。我的逻辑正确吗?

另外,当发生这种变化时,是否也可以更改提交按钮的值?

jquery addclass

0
推荐指数
1
解决办法
2万
查看次数

如果输入为空则添加类,如果不为空则删除它

如果输入为空,我想添加一个类,如果不是,则删除它。我最初有addClass();所以我尝试使用:

.removeClass().addClass();
Run Code Online (Sandbox Code Playgroud)

但它似乎并没有在单击按钮时更新类。

HTML:

<input id="firstName" type="text" />
<input id="lastName" type="text" />
<a href="#" id="button">SEND</a>
Run Code Online (Sandbox Code Playgroud)

jQuery:

var firstName = $("#firstName");
var lastName = $("#lastName");

$('#button').click(function () {
    if(firstName.val() == "" || lastName.val() == ""){
        firstName.removeClass("errorInput").addClass("errorInput");
        lastName.removeClass("errorInput").addClass("errorInput");
    }

if ($(":input").hasClass("errorInput")) {
        alert("false");
    } else {
        alert("true");
    }
});
Run Code Online (Sandbox Code Playgroud)

JSFiddle

javascript jquery addclass input removeclass

0
推荐指数
1
解决办法
2万
查看次数

jQuery:选择子元素,但我想更改父元素?

我对jQuery有疑问

<ul class="tabs">
    <li class="active"><a href="#doc-new">Home</a></li>
    <li><a href="#doc-fav">Profile</a></li>
    <li><a href="#doc-read">Messages</a></li>
</ul>
Run Code Online (Sandbox Code Playgroud)

如何使用jQuery设置active for <li>with <a>href是doc-read

<ul class="tabs">
        <li><a href="#doc-new">Home</a></li>
        <li class="active"><a href="#doc-fav">Profile</a></li>
        <li><a href="#doc-read">Messages</a></li>
</ul>
Run Code Online (Sandbox Code Playgroud)

我可以找到#doc-read但不知道怎么addClass做父母<li>.

jquery addclass selector removeclass

-1
推荐指数
1
解决办法
1257
查看次数

在 javascript addclass 之后它添加了类但 css 属性不起作用

请有人帮助我吗?我的网页是:http : //etinklapis.lt/

这里 .header-line after scroll 有一个额外的类 .header-line .active 但 css 看不到它并且不会改变背景颜色。你可以看到我的 css,那里 .header-line .active 是带有 background-color 属性的。为什么我的背景还是透明的?

CSS:

.header-line {
  width: 100%;
  height: 60px;
  background-color: rgba(255,255,255,0.00);
}
.header-line .active {
  background-color: white;
}
Run Code Online (Sandbox Code Playgroud)

标题:

<div class="header-line">header</div>
Run Code Online (Sandbox Code Playgroud)

Javascript:

$(function() {
  $(window).on("scroll", function() {
    if($(window).scrollTop() > 50) {
      $(".header-line").addClass("active");
    } else {
      //remove the background property so it comes transparent again (defined in your css)
      $(".header-line").removeClass("active");
    }
  });
});
Run Code Online (Sandbox Code Playgroud)

javascript css addclass

-1
推荐指数
1
解决办法
1520
查看次数

如何选择div的其余部分?

我遇到了问题

<div id='parent'>
  <div id='child'>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

我想要的是当孩子被点击addClass,当其余的父母被点击removeClass,所以当我尝试做

$('#child').click(function(){
  $(this).addClass();
})
$('#parent').click(function(){
  $('#child').removeClass();
})
Run Code Online (Sandbox Code Playgroud)

它不起作用我认为它是因为孩子实际上在父母的内部,所以当孩子被点击时,父母点击了吗?

那我该怎么办呢?

javascript jquery addclass removeclass

-2
推荐指数
1
解决办法
60
查看次数

jQuery addClass到h1

我正在尝试根据h1元素中的文本向h1元素添加一个类.

var title = $("h1").text();
if (title == "Welcome") {
$("h1").addClass("hide");
}
Run Code Online (Sandbox Code Playgroud)

http://jsfiddle.net/4LjnT/

html jquery addclass

-2
推荐指数
1
解决办法
938
查看次数

Jquery removeClass/addClass不起作用

如果已经有一个类,我需要在点击时向元素添加类并删除它.如果我删除"removeClass"行,"addClass"正常工作.

$(".tagy li").click(function() {
$(this).find(":input").click();   

$(this).toggleClass('lselected');

});
Run Code Online (Sandbox Code Playgroud)

你能帮助我吗,我做错了什么?谢谢你,米哈尔


如果我通过输入单击删除行,toggleClass正常工作,但我需要保留它.测试:http://mbehal.cz/trat238/test/nggallery/thumbnails?f39=1&f50=1&submit=Filtrovat#1870-1920

jquery addclass removeclass

-2
推荐指数
1
解决办法
406
查看次数

jquery中的addClass不起作用

不知道这里有什么问题.所有其他代码工作正常并且已经永远但现在我只是尝试将另一个类添加到您单击的元素并且该函数仍然正常工作它似乎忽略了我的.addClass().

$('.item-main-section, .item-status').click( function () {
    var slideHeight = $(this).parent().children('.item-slide-section').height();

    //Not Doing Anything 

    if ($('item-slide-section').hasClass('current-open')) {
        $('item-slide-section').removeClass('current-open');
    }
    $(this).parent().children('item-slide-section').addClass('current-open');

    //Not Doing Anything ^^^^

        if ($(this).parent().height() > 50) {
            $(this).parent().animate({height: '50px'}, 300);
            $(this).parent().children('item-slide-section').animate({bottom: '0px'}, 300);
        } else {
            $(this).parent().animate({height: slideHeight + 50 + 'px'}, 300);
            $(this).parent().children('item-slide-section').animate({bottom: slideHeight - 5 + 'px'}, 300);
            $(this).parent().siblings('.item-wrapper').animate({height: '50px'}, 300);
            $(this).parent().siblings('.item-wrapper').children('item-slide-section').animate({bottom: '0px'}, 300);
        }
    });
Run Code Online (Sandbox Code Playgroud)

jquery addclass

-3
推荐指数
1
解决办法
95
查看次数

标签 统计

addclass ×8

jquery ×7

removeclass ×4

javascript ×3

css ×1

html ×1

input ×1

selector ×1