天天看点

[JavaScript基础]-- 获取当前td所在的行和列位置,以及td中input的值

璇疯濡備笅浠g爜涓句緥锛?<%@ page language="java"  pageEncoding="GBK"%>
 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
 <%
 String path = request.getContextPath();
 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
 %>
 <html>
   <head>
     <base href="<%=basePath%>">
 <meta http-equiv="pragma" content="no-cache">
 <meta http-equiv="cache-control" content="no-cache">
 <meta http-equiv="expires" content="0">    
 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 <meta http-equiv="description" content="This is my page">
 <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/jquery-ui-1.9.2.custom.css"/>
 <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.8.3.js" ></script>
 <script type="text/javascript" src="${pageContext.request.contextPath}/js/kindeditor.js" ></script>
 <script type="text/javascript" src="${pageContext.request.contextPath}/js/easyui-lang-zh_CN.js" ></script>
 <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-ui-1.9.2.custom.js" ></script>
 <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.ui.datepicker-zh-CN.js" ></script>
 <script type="text/javascript">
 $(function(){
 //鐐瑰嚮"鍒犻櫎"鎸夐挳鏃讹紝寮傛淇敼鏃堕棿鍜屽垹闄? $(".closeButton").live("click",function(){
//鑾峰彇褰撳墠td鐨勮浣嶇疆
 var row=$(this).parent().prevAll().length;
//鑾峰彇褰撳墠td鐨勫垪浣嶇疆
 var col=$(this).prevAll().length;           
//鑾峰彇鎵€鏈夌殑input鍊?        /*绗竴绉嶆柟娉曪紝閬嶅巻鎵€鏈塱nput鐨勫€?  jQuery('tr td input').each(function(){
 alert(jQuery(this).val());
   });
 */
    var allKssj=document.getElementById("fqsjTable").getElementsByTagName("input");
//鑾峰彇褰撳墠杈撳叆鏃堕棿锛屾埅鍙栨牸寮忥細鈥?016-02-02 16:22:00鈥? var nowInput=allKssj[row].value.substring(0,19);

/*閬嶅巻鎵€鏈夌殑input
  for(var i=0;i<allKssj.length;i++)
    {  
     if(allKssj[i].type=='text')
     {
     alert(i);
     alert(allKssj[i].value);
     }
     }*///鑾峰彇褰撳墠閫夋嫨鐨勯棬搴楀彿鍜宨d
 var hdbh=$(this).prev().prev().prev().text();
 var id=$(this).prev().prev().prev().prev().text();
       alert(nowInput);
 //alert(kssj);
 // alert(hdbh);
 //alert(id);
 });
 //鏃ユ湡鎻掍欢
 $(".kssjTime").datepicker({
 dateFormat:'yy-mm-dd'+' 06:00:00'
 });//寮傛娣诲姞鏃堕棿
 function getDate(){
 var time2="<c:out value='${requestScope.ooc.kssj}'/>";
 if(time2==""){
 $.ajax({
 type:"post",
 contentType:"application/x-www-form-urlencoded;charset=GBK",//杩欏彞寰堥噸瑕侊紝濡傛灉娌℃湁杩欒浠g爜锛屽垯鍙湁鍦ㄧ伀鐙愪腑鍙互浣跨敤锛? url:"${pageContext.request.contextPath}/common/getDate",
 success:function(ret){
 $("#time").val(ret);
 },
 dataType:"JSON"
 });
 }
 }
 </script>
   </head>
   
   <body onLoad="getDate();">
     <c:if test="${not empty requestScope._testMdPage.fqsjList}">
     <table  id="fqsjTable" border="1" cellpadding="0"  cellspacing="0"  style="padding: 2px;" width="100%;">
     <tr>
     <td colspan="9" align="center"><font size="4" color="blue" ><strong>娲诲姩鍙戝埜鏃堕棿娈?lt;/strong></font></td>
     </tr>
     <tr>
     <td><strong>鏈€澶у彂鏀鹃噺</strong></td>
     <td><strong>鍓╀綑鏁伴噺</strong></td>
     <td><strong>缁撴潫鏃堕棿</strong></td>
     <td><strong>鐢熸垚鏃堕棿</strong></td>
     <td><strong>鍙戝埜鏃堕棿id</strong></td>
     <td><strong>娲诲姩缂栧彿</strong></td>
     <td><strong>鏄惁鏈夋晥</strong></td>
     <td><strong>寮€濮嬫椂闂?lt;/strong></td>
     <td align="center"><font color="blue"><strong>鎿嶄綔</strong></font></td>
     </tr>
     <c:forEach items="${requestScope._testMdPage.fqsjList}"  var="p">
     <tr>
     <td><c:out value="${p.ffsl}"/></td>
     <td><c:out value="${p.sysl}"/></td>
     <td><c:out value="${p.jssj}"/></td>
     <td><c:out value="${p.scsj}"/></td>
     <td><c:out value="${p.id}"/></td>
     <td><c:out value="${p.hdbh}"/></td>
     <td><c:out value="${p.sfyx}"/></td>
     <td><INPUT type="text" class="kssjTime" value="<c:out value='${p.kssj}'/>" /></td>
     <td align="center" class="closeButton"><button>鍏抽棴娴嬭瘯</button></td>
     </tr>
     </c:forEach>
     </table>
     </c:if>
     <br/>
   </body>
 </html>      

继续阅读