开发者

simple jquery trigger help

开发者_Python百科I have two icons, when I click first icon I want to appear some bunch of text somewhere on the website and when I click 2nd icon the text from the 1st icon to disappear automatically. Thanks.


You could do something like this:

<img src="http://img.vmessages.com/icon/dogs/61.gif" id="show" />
<img src="http://img.vmessages.com/icon/dogs/65.gif" id="hide" />
<div id="textDiv">This is the div with some text</div>

$('#textDiv').hide();

$('img#show').click(function(){
    $('#textDiv').show();    
});

$('img#hide').click(function(){
    $('#textDiv').hide();    
});

http://jsfiddle.net/jasongennaro/AQgv8/


Lets suppose you have 2 icons and you want to insert/remove the text on MyDiv.

So the we are binding the click event on the icon. (icons names are 1stIcon, 2ndIcon)

$(document).ready(function(){
  // First Icon Click
  $('#1stIcon').bind('click', function(){
    $('#MyDiv').val('SOME TEXT');
  });

  // Second Icon Click    
  $('#2ndIcon').bind('click', function(){
    $('#MyDiv').val('');
  });

});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜