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

请见如下代码举例:

<%@ 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值
       /*第一种方法,遍历所有input的值
 jQuery('tr td input').each(function(){
alert(jQuery(this).val());
  });
*/
   var allKssj=document.getElementById("fqsjTable").getElementsByTagName("input");
//获取当前输入时间,截取格式:“2016-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);
    }
    }*/

//获取当前选择的门店号和id
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",//这句很重要,如果没有这行代码,则只有在火狐中可以使用;
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>活动发券时间段</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>开始时间</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>

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

往事随风ing

你的鼓励将是我创作的最大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值