JS鼠标双击事件 onDblClick
<td width="10%" title="双击修改" ondblclick="ShowElement(this,<%#Eval("id") %>
</td>
</td>
这里的本人用绑定的值是传的当前行对应的ID号,
function ShowElement(element, productid, flag, ishotorcommend) {
if (flag == 0 && ishotorcommend == 0) {
alert("请先设置该产品为推荐");
return;
}
if (flag == 1 && ishotorcommend == 0) {
alert("请先设置该产品为热销");
return;
}
var oldhtml = element.innerHTML;//原单元格里的值
var str = "<input type='text' name='test' style='50%;'";
str += "onkeypress='return event.keyCode>=48&&event.keyCode<=57||event.keyCode==46'";
str += "onpaste='return !clipboardData.getData('text').match(/\D/)'";
str += "ondragenter='return false' />";
var newobj = document.createElement(str); //创建新的input元素
newobj.setAttribute("value", oldhtml);//把原来单元格中的值赋给文本框
newobj.onblur = function() {
element.innerHTML = this.value ? this.value : oldhtml; //当触发时判断新增元素值是否为空,为空则不修改,并返回原有值
var sort = element.innerHTML;
$.get("UpdateFlag.ashx?sort=" + sort + "&&productid=" + productid + "&&flag=" + flag, function(data) { });
}
element.innerHTML = '';
element.appendChild(newobj);//把新的值赋到单元格
newobj.focus();
}
if (flag == 0 && ishotorcommend == 0) {
alert("请先设置该产品为推荐");
return;
}
if (flag == 1 && ishotorcommend == 0) {
alert("请先设置该产品为热销");
return;
}
var oldhtml = element.innerHTML;//原单元格里的值
var str = "<input type='text' name='test' style='50%;'";
str += "onkeypress='return event.keyCode>=48&&event.keyCode<=57||event.keyCode==46'";
str += "onpaste='return !clipboardData.getData('text').match(/\D/)'";
str += "ondragenter='return false' />";
var newobj = document.createElement(str); //创建新的input元素
newobj.setAttribute("value", oldhtml);//把原来单元格中的值赋给文本框
newobj.onblur = function() {
element.innerHTML = this.value ? this.value : oldhtml; //当触发时判断新增元素值是否为空,为空则不修改,并返回原有值
var sort = element.innerHTML;
$.get("UpdateFlag.ashx?sort=" + sort + "&&productid=" + productid + "&&flag=" + flag, function(data) { });
}
element.innerHTML = '';
element.appendChild(newobj);//把新的值赋到单元格
newobj.focus();
}