English 中文(简体)
可能在Click上改变背景模型,然后在随后自动改变?
原标题:Possible to change background-color onClick, then automatically change back a second later?

Noob, I m, working on a brief Javascript comor, and I m using list (li) for htons. 我希望亲子关系会改变浮标,但随后将自动改变一半。 因此,我基本上希望纽伦点击新颜色,而不是gle。

这是可能的吗?

Edit:这是我现在的头脑,但它仍然没有工作:

$(li).click(function() {
    var $elem = $(this);
    var oldBG = $elem.css( backgroundColor ));
    $elem.css( backgroundColor ,  #FFFFFF ).delay(1000).css( backgroundColor , oldBG);
});

和我的标签:

<li class="key" onClick="calc( 7 )">7</li>
最佳回答
$( .key ).click(function() {
  // make a jQ collection of the DOM element from the event
  var $elem = $(this);
  // store the background-color
  var oldBG = $elem.css( background-color );
  // change the background color to what you want
  $elem.css( backgroundColor ,  #FF0000 );
  // after 1 second, change it back
  setTimeout(function() {
    $elem.css( background-color , oldBG);
  }, 1000);
}); 

rel=“nofollow noreferer”>working samples

j 如果你重入 the-col果树,则贵颜色数值会与 the合。

问题回答

保证是可能的。

规定时间的文件

这里与你开始联系。

http://www.w3schools.com/js/js_timing.asp

如果是的话,你可以使用每个纽芬兰语,但每个纽伦语是“带”;

a:active {

To change the way the buttons look when pressed. http://www.w3schools.com/CSS/css_pseudo_classes.asp

您可在点击时添加一个背景色体,并使用<编码>>>准时功能将其删除:

$(function(){
  $( li ).click(function(){
    var e = $(this);
    e.css( background-color ,  red );
    window.setTimeout(function(){
      e.css( background-color ,   );
    }, 500);
  });
});

(说明:在jQquery有delay<>/code>方法,但该方法旨在用动画取代settimeout。)

工作实例:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="sv" xml:lang="sv">
<head>
<title>Test</title>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript">

$(function(){
  $( li ).click(function(){
    var e = $(this);
    e.css( background-color ,  red );
    window.setTimeout(function(){
      e.css( background-color ,   );
    }, 500);
  });
});

function calc(digit) {
    var lcd = $( #lcd );
    lcd.text(lcd.text() + digit);
}

</script>

</head>
<body>

<div id="lcd"></div>

<ul>
  <li class="key" onClick="calc( 1 )">1</li>
  <li class="key" onClick="calc( 2 )">2</li>
  <li class="key" onClick="calc( 3 )">3</li>
  <li class="key" onClick="calc( 4 )">4</li>
  <li class="key" onClick="calc( 5 )">5</li>
  <li class="key" onClick="calc( 6 )">6</li>
  <li class="key" onClick="calc( 7 )">7</li>
  <li class="key" onClick="calc( 8 )">8</li>
  <li class="key" onClick="calc( 9 )">9</li>
  <li class="key" onClick="calc( 0 )">0</li>
</ul>

</body>
</html>




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.