双击修改某项值

$(function() {

$('td.breakword').dblclick(function(){
$(this).addClass('input').html('<input type="text" value="'+ $(this).text().replace(/[\r\n\s]/g,"") +'" />').find('input').focus().blur(function(){
var thisid = $(this).parent().siblings("th").text().replace(/[\r\n\s]/g,"");
var thisvalue=$(this).val().replace(/[\r\n\s]/g,"");

$.ajax({
type: 'POST',
url: '/modifyIntelScanError',
data: "id="+thisid+"&breakword="+thisvalue,
success:function(result)
{
if(result!="success")
{
alert(result);
}
}
});
$(this).parent().removeClass('input').html($(this).val() || 0);
});
}).hover(function(){
$(this).addClass('hover');
},function(){
$(this).removeClass('hover');
});

})

  在页面中的代码

<tr>
<th>
1
</th>
<td class="breakword" id="1" title="双击可修改">
111
</td></tr>

  

以上代码并不完整,大致意思就是,双击 class 为breakword 的td,将会将此td 替换为 一个input,原来的值为input的默认值,当焦点离开input 时,就会调用ajax,用于将修改的值进行处理


作者:panie