`

弹窗列表操作-javascript

阅读更多
<html>
<head>

<style> 

/*弹窗样式*/

.theme-buy { 
margin-top: 7%; 
text-align: center; 
} 

.theme-signin { 
font-size: 15px; 
} 

.theme-popover-mask { 
z-index: 100; 
position: absolute; 
left: 0; 
top: 0; 
width: 100%; 
height: 100%; 
background: #000; 
opacity: 0.5; 
filter: alpha(opacity = 50); 
-moz-opacity: 0.5; 
display: none; 
} 

.theme-popover { 
z-index: 200; 
position: absolute; 
top: 40%; 
left: 40%; 
width: 1000px; 
height: 540px; 
margin: -180px 0 0 -330px; 
border-radius: 5px; 
border: solid 2px #e4e4e4; 
background-color: #fff; 
display: none; 
box-shadow: 0 0 10px #666; 
background: #fff; 
} 

.theme-poptit { 
border-bottom: 1px solid #ddd; 
padding: 12px; 
position: relative; 
height: 24px; 
} 

.theme-poptit .close { 
float: right; 
color: #999; 
padding: 5px; 
margin: -2px -5px -5px; 
font: bold 14px/14px simsun; 
text-shadow: 0 1px 0 #ddd 
} 

.theme-poptit .close:hover { 
color: #444; 
} 

.theme-popbod { 
padding: 60px 15px; 
color: #444; 
height: 148px; 
} 

.dform { 
padding: 10px 10px 10px; 
text-align: left; 
} 

.theme-signin { 
margin: -50px -20px -50px 90px; 
text-align: left; 
font-size: 14px; 
} 

.theme-signin li { 
padding-left: 30px; 
margin-bottom: 15px; 
} 

.theme-signin li strong { 
float: left; 
margin-left: -80px; 
width: 80px; 
text-align: right; 
line-height: 32px; 
} 

.theme-signin .btn { 
margin-bottom: 10px; 
} 

.theme-signin p { 
font-size: 12px; 
color: #999; 
} 

.theme-popover-mask-dialog { 
z-index: 100; 
position: absolute; 
left: 0; 
top: 0; 
width: 100%; 
height: 100%; 
background: #000; 
opacity: 0.5; 
filter: alpha(opacity = 50); 
-moz-opacity: 0.5; 
display: none; 
} 

/* .theme-popover-dialog { 
z-index: 200; 
position: absolute; 
top: 160%; 
left: 60%; 
width: 400px; 
height: 500px; 
margin: -180px 0 0 -330px; 
border-radius: 5px; 
border: solid 2px #e4e4e4; 
background-color: #fff; 
display: none; 
box-shadow: 0 0 10px #666; 
background: #fff; 
} */ 

.theme-popover-dialog { 
z-index: 200; 
position: fixed; 
top: 25%; 
left: 35%; 
width: 750px; 
height: 500px; 
margin: -100px 0px 0px -150px; 
border-radius: 5px; 
border: solid 2px #e4e4e4; 
background-color: #fff; 
display: none; 
box-shadow: 0 0 10px #666; 
background: #fff; 
} 


.theme-poptit-dialog { 
border-bottom: 1px solid #ddd; 
padding: 12px; 
position: relative; 
height: 24px; 
} 

.theme-poptit-dialog .close { 
float: right; 
color: #999; 
padding: 5px; 
margin: -2px -5px -5px; 
font: bold 14px/14px simsun; 
text-shadow: 0 1px 0 #ddd 
} 

.theme-poptit-dialog .close:hover { 
color: #444; 
} 

.theme-popbod-dialog { 
padding: 60px 15px; 
color: #444; 
height: 248px; 
overflow-y:auto; 
} 

/* input */ 
.ipt { 
border: solid 1px #d2d2d2; 
border-left-color: #ccc; 
border-top-color: #ccc; 
border-radius: 2px; 
box-shadow: inset 0 1px 0 #f8f8f8; 
background-color: #fff; 
padding: 4px 6px; 
height: 21px; 
line-height: 21px; 
color: #555; 
width: 180px; 
vertical-align: baseline; 
} 

.ipt:focus { 
border-color: #95C8F1; 
box-shadow: 0 0 4px #95C8F1; 
} 

</style> 

<style>

/*查询表格样式*/
.wideT{ border-top:3px solid #D4D4D4}
.wideTable, .wideTable td{ border-collapse:collapse; font-size:13px;}
.wideTable td{ border:1px dashed #dcdcdc; border-width:1px 0; border-collapse:collapse; text-align:center; padding:5px 2px;}
.wideTable td.tabR{ text-align:right}
.wideTable td.tabL{ text-align:left}

.wideTable td a{  padding:0 15px 0 10px;}
td.moreOut{  width:200px;}
.moredo{ display:inline-block; float:left;}
.moredoNow{ position:absolute; margin-top:-11px; *margin-top:-22px;background:#fff ;display:block; z-index:1;border:1px solid #959595; 
-moz-border-radius:3px;-khtml-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;
 -webkit-box-shadow:0px 0px 5px #c0c0c0;-moz-box-shadow:0px 0px 5px #c0c0c0;}
 
 
 .wideTable thead td{ border:0; background:#e2ebf4; font-weight:bold; padding:7px 2px;}
.wideTable tfoot td{ border:1px solid #e1e1e1;border-width:1px 0; text-align:right; padding-right:15px; font-size:12px;}
.wideTable tfoot td a { border:1px solid #d5d5d5; padding:5px 10px; color:#696969; line-height:24px; margin-left:4px;}
.pagesNo{border:1px solid #d5d5d5; color:#696969; height:24px; display:inline-block; margin-left:4px; padding:0;}
input.pNo{ line-height:18px; border:0; width:20px; vertical-align:middle}
input.pGo{ line-height:20px; border:0; vertical-align:middle}

.wideTable tr.even td{ background:#f8f8f8}
.wideTable tr.pass td{ background:#f6ffc6}

</style>

<style>

/*css reset*/
html, body, div, span, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, code, del, dfn, em, img, q, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td {
	margin:0;
	padding:0;
	border:0;
	font-weight:inherit;
	font-style:inherit;
	font-size:100%;
	font-family:inherit;
	vertical-align:baseline;
}
body {line-height:1.5;}
table {border-collapse: collapse;border-spacing:0;}
caption, th, td {text-align:left;font-weight:normal;}
table, td, th {vertical-align:middle;}	
blockquote:before, blockquote:after, q:before, q:after {content:"";}
blockquote, q {quotes:"" "";}
a img {border:none;}


body { background:#fff; font: 12px/1.5 Tahoma, Helvetica, Arial, sans-serif ;color:#666;}
h1, h2, h3, h4, h5, h6 {font-weight:normal;color:#111;font-size:12px; }
a:focus, a:hover {color:#000;}
a {color:#009;text-decoration:none;}
dl, dt, dd, ol, ul, li{ list-style:none;}

</style>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>



</head>

<body>


<input type="button" value="弹窗" onclick="hidedialog();"/>

<div class="theme-popover-dialog"> 
<div class="theme-poptit-dialog"><a href="javascript:;" title="关闭" 
class="close">×</a> 
<h3>信息</h3> 
</div> 
<div class="theme-popbod-dialog dform"> 
<span id="spanTitle" style="color:red"></span> 
<table id="myTableQh" width="100%" border="0" class="wideTable"> 
<thead id="myTheadQh"> 
<tr> 
<td>参数1</td> 
<td>参数1</td> 
<td>参数1</td> 
<td>参数1</td> 
<td >操作</td> 
</tr> 
</thead> 
<tbody id="myTbodyQh"> 

</tbody> 
<tfoot id="myTfootQh"> 

<tr> 
<td class="tabL" colspan="5"><input name="input2" type="button" value="新增" class="buttonGray" onclick="addTableRecord();"/></td> 
</tr> 


</tfoot> 


</table> 
</div> 

<div> 

<input class="buttonGray" type="button" name="submit" 
onclick="assignValue();" value=" 保存 " /> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<input 
class="buttonGray" id="closemoreFile" type="button" name="submit" 
onclick="closedialog();" value=" 关闭 " /> 
</div> 


</div> 
<div class="theme-popover-mask-dialog"></div> 



<script> 

function hidedialog(){ 


$('.theme-popover-mask-dialog').show(); 
$('.theme-popover-mask-dialog').height($(document).height()); 
$('.theme-popover-dialog').slideDown(200); 

//initData(); 
  
} 

function closedialog() 
{ 
$('.theme-popover-mask-dialog').hide(); 
$('.theme-popover-dialog').slideUp(200); 
} 

$(document).ready(function($){ 
$('.theme-poptit .close').click(function(){ 
$('.theme-popover-mask').hide(); 
$('.theme-popover').slideUp(200); 
}); 

$('.theme-poptit-dialog .close').click(function(){ 
$('.theme-popover-mask-dialog').hide(); 
$('.theme-popover-dialog').slideUp(200); 
});     
}); 






function deleteTableRecord(obj,id){ 
if(confirm("确定要删除该数据吗?")) { 
if (id == -1) { 
$(obj).parent().parent().remove(); 
} else { 
$.ajax({ 
url: url, 
type: 'POST', 
data: {id:id}, 
dataType: 'json', 
async: false, 
success: function(jObj){ 
if(jObj.success) { 
$(obj).parent().parent().remove(); 
alert("删除成功!"); 
} else { 
alert("删除失败!"); 
} 

} 
}); 
} 
} 
} 




var idxTr = 0; 
function addTableRecord(){ 
var html = "<tr>"; 

html = html + "<td data-id='param1' edit='0' style='display: none'>-1</td>"; 
html = html + "<td data-id='param1' edit='0' style='display: none'></td>"; 

html = html + "<td data-id='param1' style='word-break: break-all;font-size:12px' ><select ></select></td>"; 
html = html + "<td data-id='param1' style='word-break: break-all;font-size:12px' ><select ></select></td>"; 
html = html + "<td data-id='param1' style='word-break: break-all;font-size:12px' edit='1'><select></select></td>"; 
html = html + "<td data-id='param1' style='word-break: break-all;font-size:12px' edit='1'></td>"; 
html = html + "<td data-id='param1' style='word-break: break-all;font-size:12px' edit='0'></td>"; 
html = html + "</tr>"; 
$(html).appendTo($("#myTbodyQh"));	
new tableEdit('myTbodyQh'); 
} 


function initData(keyId) { 


$.ajax({ 
url: url, 
type: 'POST', 
dataType: 'json', 
data: {keyId:keyId}, 
async: false, 
success: function(jObj){ 
$("#myTbodyQh").empty(); 


if(jObj.bodyList!=null && jObj.bodyList.length > 0) { 
var bodyHtml=""; 
for(var i=0; i<jObj.bodyList.length; i++) { 
var bodyObj=jObj.bodyList[i]; 

var id = bodyObj["param1"] || ""; 
var storeId = bodyObj["param1"] || ""; 

var provinceNameVal = bodyObj["param1"] || ""; 
var cityNameVal = bodyObj["param1"] || ""; 
var storeNameVal = bodyObj["param1"] || ""; 
var terminalCntVal = bodyObj["param1"] || ""; 

bodyHtml = bodyHtml + "<tr>"; 

bodyHtml = bodyHtml + "<td data-id='param1' edit='0' style='display: none'>" + param1 + "</td>"; 
bodyHtml = bodyHtml + "<td data-id='param2' edit='0' style='display: none'>" + param1 + "</td>"; 

bodyHtml = bodyHtml + "<td data-id='param3' style='word-break: break-all;font-size:12px;color:red' edit='0'>" + param1 + "</td>"; 
bodyHtml = bodyHtml + "<td data-id='param4' style='word-break: break-all;font-size:12px;color:red' edit='0'>" + param1 + "</td>"; 
bodyHtml = bodyHtml + "<td data-id='param5' style='word-break: break-all;font-size:12px;color:red' edit='0'>" + param1 + "</td>"; 
bodyHtml = bodyHtml + "<td data-id='param6' style='word-break: break-all;font-size:12px;color:red' edit='0'>" + param1 + "</td>"; 
bodyHtml = bodyHtml + "<td data-id='param7' style='word-break: break-all;font-size:12px' edit='0'></td>"; 


bodyHtml = bodyHtml + "</tr>"; 


} 
$(bodyHtml).appendTo($("#myTbodyQh")); 
} 


} 
}); 
new tableEdit('myTbodyQh'); 


} 

function valiTable() { 
var flag = true; 


return flag; 
} 

function assignValue() { 
if (!valiTable()) { 
return; 
} 

var table = $('#myTbodyQh').tableRowsToJSONWithFilter(); 

$.ajax({ 
url: url, 
type: 'POST', 
data: {param1:param1}, 
dataType: 'json', 
async: false, 
success: function(jObj){ 
// 重新加载 
initData(); 
if(jObj.success) { 
alert("保存成功!"); 

} else { 
alert("保存失败!"); 
} 

} 
}); 
} 

function deleteTableRecord(obj,id){ 
//if(confirm("确定要删除该数据吗?")) { 
if (id == -1) { 
$(obj).parent().parent().remove(); 
} else { 
$.ajax({ 
url: url, 
type: 'POST', 
data: {id:id}, 
dataType: 'json', 
async: false, 
success: function(jObj){ 
if(jObj.success) { 
$(obj).parent().parent().remove(); 
alert("删除成功!"); 
} else { 
alert("删除失败!"); 
} 

} 
}); 
} 
//} 
} 

</script>

<script>



function tableEdit(table) { 
table = table || document.getElementsByTagName("table")[0]; 
var tab = (typeof(table) == "string" || typeof(table) == "String") ? document.getElementById(table) : table; 
var td = $(tab).find('td'); 
td.click(tdClick); 
} 


function validate(table) 
{ 
table = table || document.getElementsByTagName("table")[0]; 
var tab = (typeof(table) == "string" || typeof(table) == "String") ? document.getElementById(table) : table; 
$(tab).find('td').each(function(){ 
var len = $(this).attr('maxLength'); 
var reg = $(this).attr('reg'); 
var isNill = $(this).attr('isNill'); 
}); 
} 

function tdClick(){ 
    //将td的文本内容保存 
attr = $(this).attr('edit'); 
if (attr !== undefined && attr == '0') { 
return; 
} 

   if($(this).has('select').length>0) 
   { 
      return; 
   } 
   var len = $(this).attr('maxLength'); 
   var reg = $(this).attr('reg'); 
   var regMsg = $(this).attr('regMsg'); 
   
   var td = $(this); 
   var tdText = td.text(); 
    //将td的内容清空 
   td.empty(); 
    //新建一个输入框 
   var input = $("<input>"); 
    //将保存的文本内容赋值给输入框 
   input.attr("value",tdText); 
    //将输入框添加到td中 
   td.append(input); 
    //给输入框注册事件,当失去焦点时就可以将文本保存起来 
   input.blur(function(){ 
        //将输入框的文本保存 
        var input = $(this); 
        var inputText = input.val(); 
        var msg = ""; 
        
        if(len !== undefined){ 
    len = parseInt(len); 
    if(inputText.length>len){ 
  alert(inputText+"长度过长,不能超过"+len+"位"); 
  window.setTimeout(function () { input.focus();}, 0); 
  return false; 
    }	  
          } 
        if(reg !== undefined){ 
        var patt1=new RegExp(reg); 
        if(!patt1.test(inputText)){ 
        if(regMsg !== undefined){ 
                alert(regMsg); 
                window.setTimeout(function () { input.focus();}, 0); 
            return false; 
            }else 
            { 
            alert(inputText+"格式不正确"); 
                window.setTimeout(function () { input.focus();}, 0); 
            return false; 
            } 
                 } 
         } 
        
        //将td的内容,即输入框去掉,然后给td赋值 
        var td = input.parent("td"); 
        td.html(input.val()); 
        //让td重新拥有点击事件 
        td.click(tdClick); 

   }); 
    input.keyup(function(event){ 
        //1.获取当前用户按下的键值 
             //解决不同浏览器获得事件对象的差异, 
             // IE用自动提供window.event,而其他浏览器必须显示的提供,即在方法参数中加上event 
           var myEvent = event || window.event; 
           var keyCode = myEvent.keyCode; 
           //2.判断是否是ESC键按下 
          if(keyCode == 27){ 
               //将input输入框的值还原成修改之前的值 
              input.val(tdText); 
           } 
    }); 
   //将输入框中的文本高亮选中 
   //将jquery对象转化为DOM对象 
   var inputDom = input.get(0); 
    inputDom.select(); 
    //将td的点击事件移除 
   td.unbind("click"); 
} 




(function($) { 
  $.extend($.fn, { 
    tableRowsToJSONWithFilter : function (filter) { 
      var tableSelector = this, item, attr,len, data, _JSON = []; 
      if (typeof(tableSelector) !== 'object') { 
        return new Error('Invalid tableSelect!'); 
      }; 
      $(tableSelector).find('tr').each(function(index, tr) { 
        item = {}; 
        $('td', $(this)).each(function(index, td) { 
          attr = $(td).attr('data-id'); 

  if($(td).has('select').length>0) 
  { 
data = $(td).children('select').val(); 
  } 
                  else if ($(td).has('input:radio').length>0) { 
data = $(td).children('input:radio:checked').val(); 
  } 
  else 
  { 
      data = $(td).text(); 
  } 
  
          if (attr !== undefined && data !== '') { 
            item[attr] = $.trim(data); 
          }; 
        }); 
        _JSON.push(item); 
      }); 
      return _JSON; 
    } 
  }) 
})(jQuery);

</script>



</body>

</html>
分享到:
评论

相关推荐

    弹窗小技巧-div

    在ASP.NET开发中,弹窗是一种常见的用户交互方式,它能提供信息提示、确认操作或者展示详细内容。本文将深入探讨如何使用div元素实现类似微博的弹窗效果,并结合ASP.NET的技术栈,来构建一个实用的弹窗功能。 首先...

    弹窗上传--An-Upload无组件上传类8.8.19 示例

    3. index.asp - 这通常是一个网页的入口文件,展示上传功能的前端界面,可能包含调用An-Upload库的JavaScript代码和触发弹窗的按钮。 4. cssjs.asp - 这可能包含了样式表(CSS)和JavaScript文件,用于美化上传界面...

    网站弹窗公告源码-一天只弹一次.zip

    在网页开发中,弹窗公告通常由JavaScript语言实现,因为它可以动态地与用户进行交互。JavaScript代码可能包括一个函数,该函数检查用户的cookie或本地存储来判断公告是否已经展示过。如果用户在当前浏览器会话中尚未...

    web弹窗插件 layer-v3.1.1

    2. 调用API:通过JavaScript调用`layer.open()`方法,传入配置对象以创建弹窗。 3. 关闭弹窗:可以使用`layer.close()`方法关闭指定的弹窗。 ### 四、示例代码 ```javascript // 创建一个简单的提示信息 layer.msg...

    Js封装的弹窗表单-xForm

    在JavaScript编程中,"xForm"是一个常见的用于创建弹窗表单的小型插件。它旨在简化网页中动态创建和管理表单的过程,提供一种高效、灵活的方式,以减少开发者编写重复代码的时间。以下是关于"Js封装的弹窗表单-xForm...

    气泡弹窗.popover

    在移动应用和网页设计中,气泡弹窗(Popover)是一种常见的交互元素,用于提供额外的信息或者操作选项。它通常以一个小窗口的形式出现,里面包含着用户可能需要的提示或者功能菜单。Popover的命名来源于其外观特性,...

    广告弹窗拦截源码-易语言

    【标题】"广告弹窗拦截源码-易语言"揭示了这个压缩包文件的主要内容,即一份使用易语言编写的广告弹窗拦截程序的源代码。易语言是一种以中文编程为特色的编程语言,旨在降低编程的难度,让更多人能够参与到编程中来...

    jsp界面出弹窗效果(可以放列表,也可以放详情等内容)

    在标题为“jsp界面出弹窗效果(可以放列表,也可以放详情等内容)”的主题中,我们主要探讨的是如何在JSP(JavaServer Pages)页面上实现弹窗功能,这种弹窗不仅能够展示列表数据,还能展示详细信息。这通常涉及到...

    快应用-弹窗功能-声明.zip

    在快应用中,弹窗功能是实现交互和提示用户的重要手段,尤其在通知、确认操作或展示信息时显得尤为重要。本资源针对快应用中的弹窗功能进行了详细的阐述,帮助开发者更好地理解和使用这一特性。 首先,我们要了解...

    小程序-弹窗-Modal.rar

    在微信小程序开发中,弹窗(Modal)是一个非常常见的组件,用于向用户展示重要的提示信息或者需要用户进行确认的操作。本资源"小程序-弹窗-Modal.rar"显然包含了一个关于如何在小程序中实现Modal弹窗的示例或教程。...

    coco-modal弹出窗demo.rar

    Coco-Modal是一款轻量级、易用的JavaScript弹出窗口插件,它为开发者提供了在网页中创建各种类型弹窗的功能,如信息提示、确认对话框、模态窗口等。这款插件的设计目标是兼容主流浏览器,确保在不同的设备和环境中都...

    一个弹窗案例

    在IT行业中,弹窗是一种常见的用户界面元素,用于在网页或应用中显示临时信息或进行交互操作。这个“一个弹窗案例”似乎提供了一个简洁易用的弹窗组件,可以帮助开发者快速实现弹窗功能。接下来,我们将深入探讨弹窗...

    隐私弹窗页面-pages文件

    2. **前端开发**:使用"stml"或其他类似语言来编写弹窗页面,需要理解基本的前端编程概念,如DOM操作、CSS样式、JavaScript事件处理等。 3. **响应式设计**:为了适应不同设备和屏幕尺寸,隐私弹窗页面应具备响应式...

    JavaScript弹窗插件

    JavaScript弹窗插件是一种在网页上实现交互式提示或通知功能的工具,它通常通过JavaScript编程语言来编写,可以提供丰富的用户体验。JavaScript是Web开发中的重要脚本语言,它允许开发者在用户与网页之间建立动态...

    基于layui点击按钮弹出包含表单的窗口

    layui的每个功能都被封装为一个模块,例如`form`模块用于处理表单操作,`layer`模块则用于弹窗功能。在使用前,我们需要通过`layui.use()`方法引入这些模块。 1. 引入layui库: 在HTML文件头部引入layui的CSS和JS...

    24小时弹窗一次的代码

    ### 24小时弹窗一次的JavaScript代码解析 在网页设计与开发中,为了提升用户体验并考虑到搜索引擎优化(SEO)的需求,合理地使用弹窗功能是非常重要的。本篇文章将详细介绍如何实现“24小时弹窗一次”的功能,通过...

    jQuery实现网页打开页面即弹窗

    在网页设计中,弹窗是一种常见的交互方式,用于显示重要的信息或者引导用户操作。jQuery,一个广泛使用的JavaScript库,提供了简洁的API来简化DOM操作,使得创建动态和交互性的网页变得更为便捷。本教程将深入探讨...

    精品中易广告联盟网站源码3.31

    正版 无功能限制 可进后台操作 含3.31 3.32两个版本 多种可选模板 现在在这里共享出来 只要10分就可以免费下载 有需要的就拿去吧! 程序目录结构说明 app 核心文件不需要修改和变动 lib 核心文件不需要修改和变动...

    基于Jquery1.4.4的弹出提示框效果

    JQuery是一个广泛使用的JavaScript库,它极大地简化了DOM操作、事件处理、动画效果以及Ajax交互。在JQuery 1.4.4版本中,创建弹出提示框是开发网页交互性功能时常见的需求,可以用于显示警告、确认信息或用户反馈等...

    Javascript实现广告弹窗

    这段代码确保了页面加载完成后才执行弹窗的相关操作,避免了页面加载过程中出现的布局问题。 ##### 5. 弹窗触发按钮 ```html ()"&gt;点击显示广告 ``` 通过一个按钮触发弹窗的显示与隐藏。 #### 四、功能扩展与...

Global site tag (gtag.js) - Google Analytics