标签:
<script type="text/javascript" language="javascript">
//屏蔽浏览器右键
function stop(){
return false;
}
document.oncontextmenu = stop;
var i=3;
$(function() {
//点击页面其他位置右键菜单消失
$(‘body‘).bind(‘click‘, function(ev) {
$(‘#menu‘).css(‘display‘,‘none‘);
$(‘#menub‘).css(‘display‘,‘none‘);
});
var $inp = $(‘.cls‘);
$inp.bind(‘keydown‘, function(e) {
var key = e.which;
if (key == 13) {
var id = $("input:focus").attr("id");
if (id == "isAbroad2") {
addTable();
document.getElementById("name3").focus();
}
e.preventDefault();
var nxtIdx = $inp.index(this) + 1;
$(".cls:eq(" + nxtIdx + ")").focus();
}
});
//回显子表1数据
var b=$("#dcasXmsbs_2_1s").val();
if(b!=null && b!=""){
var c=b+"";
var d=c.replace(/__/g, ‘"‘);
var e=d+"";
var json=eval(‘(‘+e+‘)‘);
if(json.length<1){
}else{
for ( var s = 0; s < json.length; s++) {
if(s>2){
addTable();
}
$("#id"+s).val(json[s].id);
$("#name"+s).val(json[s].name);
$("#birthday"+s).val(json[s].birthday);
$("#nationality"+s).val(json[s].nationality);
$("#education"+s).val(json[s].education);
$("#duty"+s).val(json[s].duty);
$("#studyDirection"+s).val(json[s].studyDirection);
$("#plan"+s).val(json[s].plan);
$("#isAbroad"+s).val(json[s].isAbroad);
}
i = json.length;
}
}
});
//追加明细
function addTable() {
var s = i+1;
var tbody= "tbody" + i;
var id = "id" + i;
var name = "name" + i;
var birthday = "birthday" + i;
var nationality = "nationality" + i;
var education = "education" + i;
var duty = "duty" + i;
var studyDirection = "studyDirection" + i;
var plan = "plan" + i;
var isAbroad = "isAbroad" + i;
$("#table_buffer")
.append(
" <tbody id=\""+tbody+"\" class=‘pn-ltbody‘> "
+ "<td> "+ "<input type=\"hidden\" id=\""+id+"\" name=\""+id+"\"/>"+ "<input type=\"text\" id=\""+name+"\" name=\""+name+"\" style=\"width: 80px;\" onmouseup=\"youjian("+s+",this)\" />"+ "</td> "
+ "</tbody>");
i++;
$("#countInfo1").val(i);
}
function changeNextFocus(str, s,event) {
if (event.keyCode == 13) {
if (str == "netLine") {
addTable();
var ss = s + 1;
document.getElementById("name" + ss).focus();
} else {
str.focus();
}
}
}
//表格1
//右键事件
var rowIndex; //用于后台删除数据
var rowIndex2;//标识当前行
function youjian(a,b){
var container = document.getElementById(‘table_buffer‘);
var menu = document.getElementById(‘menu‘);
if(event.button == 2){
var evt = window.event || arguments[0];
/*获取当前鼠标右键按下后的位置,据此定义菜单显示的位置*/
menu.style.left = container.scrollLeft + evt.clientX + "px";
menu.style.top = container.scrollTop + evt.clientY +document.body.scrollTop+ "px";
/*设置菜单可见*/
$(‘#menu‘).css(‘display‘,‘block‘);
rowIndex = a;
rowIndex2 = b;
}
}
//删除行
function delRow(){
var r = rowIndex-1;
var delId1 = $(‘#delId1‘).val();
if(delId1==null || delId1 == ""){
var id = $("#id"+r).val();
$(‘#delId1‘).val(id);
}else{
$(‘#delId1‘).val(delId1+","+$("#id"+r).val());
}
document.getElementById(‘table_buffer‘).deleteRow(rowIndex2.parentNode.parentNode.rowIndex);
}
</script>
<body>
<div id="menu" class="menuSkin">
<span style="cursor: pointer;" id="shanchu" onclick="delRow()">删除</span>
</div>
</body>
标签:
原文地址:http://www.cnblogs.com/xiaoxiaoguai/p/5434011.html