我有以下jQuery函数:
1)提交表格
$(".content").delegate('.entryButton','click', function() {
var form = $(this).closest("form");
var id = form.attr('id');
var text = form.find("textarea").val();
Sijax.request('add_entry', [id, text]);
//Prevent the form from being submitted (default HTML)
return false;
});
Run Code Online (Sandbox Code Playgroud)
2)放大表格并显示输入按钮
$("textarea").focus(function() {
$(this).css('height', '80px');
var button = $(this).parent().next().children();
button.css('visibility', 'visible');
button.css('height', '20px')
});
Run Code Online (Sandbox Code Playgroud)
3)使textarea更小并隐藏按钮
$("textarea").blur(function() {
$(this).css('height', '30px');
var button = $(this).parent().next().children();
button.css('height', '0px')
});
Run Code Online (Sandbox Code Playgroud)
当我尝试输入时会发生这种情况:
我认为这意味着模糊和点击事件相互干扰?
你可以在这里找到问题的小提琴.当您按下按下该按钮的按钮时,它会使该区域模糊但不会输入该区域.当您按下按钮并且字段模糊时,该条目会被提交.
有任何想法吗?
提前致谢!
$('.entryButton').on('click', function (e) {
return false; // to prevent default form post
});
$("form").delegate('.entryButton','mousedown', function() {
$('textarea').trigger('blur');
var form = $(this).closest("form");
var id = form.attr('id');
var text = form.find("textarea").val();
$("#test").append(text);
//Prevent the form from being submitted (default HTML)
return false;
});
Run Code Online (Sandbox Code Playgroud)
并保持以前的对焦和模糊功能。
thanks.
Run Code Online (Sandbox Code Playgroud)