我正在努力创建自己的成绩单,作为AJAX.在它的基础上有一个可编辑单元格的表格.用户点击单元格以输入成绩,当他们点击单元格时,成绩将通过AJAX发送到DB.到目前为止它工作得很好,除了我添加了用户点击Enter的能力,并让它表现得好像用户点击其他地方关闭编辑表单.
问题是,当用户点击返回而不是输入时,模糊部分会运行两次,如警报弹出两次所示.如果他们只是点击某处,那很好.我对jQuery的.blur()的理解是,如果你在没有回调或参数的情况下调用它,它就会充当一个行动者并将其视为所选元素失去焦点.
发生在IE8,Chrome和FF 4.0.1上.在我的测试站点上运行的实时版本
当我尝试设置用户点击输入时的模糊时,有人可以解释为什么它会运行两次吗?
更新:无法发布HTML,因为它实际上只是一个表,而表标记集不在stackOverflow白名单中.(我是新来的,所以也许有办法做到这一点,但我不知道.)
此外,我通过改变解决了当前的问题
if(event.keyCode=='13')
{
$('#gradeUpdate').blur();
}
Run Code Online (Sandbox Code Playgroud)
至
if(event.keyCode=='13')
{
$("#gradeUpdate").parent().focus();
//$('#gradeUpdate').blur();
}
Run Code Online (Sandbox Code Playgroud)
但我仍然想知道为什么原来的线不只是让#gradeUpdate模糊,就像我想的那样.
一切都发生在这个功能内:
function clickableCell(){
$("td.assignmentCell").click(function(){ //if a td with an assignment class is clicked,
if( clicked == 0)
{
clicked = 1;
currentValue = $(this).text();//get the current value of the entered grade
var passable = this;
alert("Test: passable is: "+$(passable).text());
//change content to be an editable input form element
$(this).html("<input name='gradeUpdate' id='gradeUpdate' size=3 value='"+currentValue+"' type='text' />");
//move the cursor to the …Run Code Online (Sandbox Code Playgroud)