2011-09-05 53 views
0

我是Jquery的新手,並試圖找到一種方式來顯示額外的文本,當用戶點擊表單。Jquery:當用戶點擊表單域時如何顯示額外的文本

輸入字段看起來是這樣的:<input class="feed" id="post_title" name="post[title]" size="100" rows="20" type="text class="title_search"">和文本的其餘部分包含有<div class = "post-input">

任何指着我的方向是正確的幫助,將不勝感激:)

回答

2
$('input').focusin(function() { 
     $('div').show(); 
    }); 

    // Hide the text once you are out of the input 
    $('input').focusout(function() { 
     $('div').hide(); 
    }); 

這是基本的想法。 http://api.jquery.com/focusin/

1
$('#post_title').click(function(){ 
    $(this).next('.post-input').html('hey! you clicked the input!'); 
}); 

// asuming div在輸入旁邊,如果不是的話,我也建議給它添加一個id。

,如果有alredy文本在div,你只是想表明它

$('#post_title').click(function(){ 
     $(this).next('.post-input').show(); 
    }); 
0
$('.feed').click(function() { 
    $('.post-input').show(); 
} 
相關問題