用文本框交换textarea,反之亦然

时间:2011-10-25 11:09:47

标签: javascript jquery

以下jQuery代码无效。请检查模糊事件导致问题的演示

//code to change textbox
$('.SpeakMindInputArea').live("click",function(){
    $(this).hide().next().show(5).focus();
    $(this).next().find('textarea').first().focus();

});
$('.SpeakMindField').live("blur",function(){
    $(this).find('.SpeakMindInputArea').first().show().next().hide();        
});

演示:http://jsfiddle.net/CwZKq/

我希望点击文本框,将其更改为textarea,并在模糊后重新开始。但如果我尝试提交表格,它需要保持不变。

2 个答案:

答案 0 :(得分:1)

可能你正在寻找这样的东西:http://jsfiddle.net/CwZKq/11/

//code to change textbox
$('.SpeakMindInputArea input').live("focus",function(){
    $(this).parent().hide().next().show().find('textarea').focus();
});

$('.SpeakMindTextArea textarea').live("blur",function(){
    if ($(this).val() == '')
        $(this).parent().hide().prev().show();
});

更新:现在它处理提交:http://jsfiddle.net/CwZKq/13/

//code to change textbox
$('.SpeakMindInputArea input').live("focus",function(){
    $('.SpeakMindTextArea textarea:visible').parent().hide().prev().show();        
    $(this).parent().hide().next().show().find('textarea').focus();
});

答案 1 :(得分:1)

您可以尝试这样的事情:

$('.SpeakMindInputArea').live("focus",function(){
        $('.SpeakMindTextArea').not(this).hide().prev().show();
        $(this).hide().next().show().find('textarea').focus();
    });

在这种情况下,如果显示textarea,只有在单击其他文本框时才会隐藏。

相关问题