jquery - 了解 jQuery 中的优先级

标签 jquery css

我们要更改输入标签的属性,稍等片刻,然后再将属性改回来:

    $('input[name=produkt-rueckruf-telefon]')
        .val('Danke. Wir melden uns gleich!')
        .css({'background' : 'none'})
        .css({'border' : 'none'})
        .css({'color' : '#fff'});
    $('input[name=produkt-rueckruf-telefon]')
        .delay(3000);       
    $('input[name=produkt-rueckruf-telefon]')
        .val('')
        .css({'border' : '1px solid #fff'})
        .css({'color' : '#525353'})
        .css({'background' : '#fff'});

在此先感谢您提供有关我们在这里做错的任何提示!

最佳答案

使用setTimeout delay 而不是 delay适用于动画队列。

var $input = $('input[name=produkt-rueckruf-telefon]')
        .val('Danke. Wir melden uns gleich!')
        .css({'background' : 'none'})
        .css({'border' : 'none'})
        .css({'color' : '#fff'});
window.setTimeout(function(){
       $input.val('')
        .css({'border' : '1px solid #fff'})
        .css({'color' : '#525353'})
        .css({'background' : '#fff'});
}, 3000);

.delay() method allows us to delay the execution of functions that follow it in the queue. It can be used with the standard effects queue or with a custom queue. Only subsequent events in a queue are delayed;

作为一种替代方法,而不是使用 css 添加/删除类来设置内联样式。

.withValue{
   background : none;
   border : none;
   color : #fff;
   /*Rules*/
}

.withOutValue{
   background : #fff;
   border : 1px solid #fff;
   color : #525353;
   /*Rules*/
}

var $input = $('input[name=produkt-rueckruf-telefon]')
        .val('Danke. Wir melden uns gleich!').addClass('withValue');
window.setTimeout(function(){
       $input.val('').addClass('withOutValue').removeClass('withValue');
       //or use toggleClass
       //$input.val('').toggleClass('withOutValue withValue');
});

关于jquery - 了解 jQuery 中的优先级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19935896/

相关文章:

javascript - ul 简单的弹出菜单

javascript - 如何通过使用javascript在外部单击来隐藏弹出窗口

javascript - JQuery datepicker - 更改日期格式

javascript - 如何仅从字母数字字符串中提取字母表

javascript - 如何组合两个javascript FormData对象

jquery - 多个输入的清算值(value)?

javascript - 事件在 FireFox 中未定义,但在 Chrome 和 IE 中可以

css - 在没有脚手架的情况下 Bootstrap 响应行?

html - 由于 h2 在其上方,图像溢出容器

css - WebKit 中的神秘 1px 边框