JS获取循环表格中input的值,该怎么处理

php中文网
发布: 2016-06-13 13:33:03
原创
1855人浏览过

JS获取循环表格中input的值
请问我该如何获取到鼠标点击的tr行input的值呢?
现在获取到的是始终是第一条记录。。。。。。。



JScript code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
function popUserDetail(x){
    var popUp = document.getElementById("popUserDetail");
  var h = (x.rowIndex)*20;
        popUp.style.top= 25 + h + "px";
        popUp.style.left="142px";
        popUp.style.width="200px";
        popUp.style.height="100px";
        popUp.style.visibility="visible";      
      var customerId = document.getElementsByTagName("input")[0].value;
    alert (customerId);
    }

登录后复制



PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
           while ($records = mysql_fetch_array($rows)) 
              { 
                  $arr = ct($records['uniqueid']);
                  $fileLastUploadTime  = $arr[1];
             
       print       '
                    <tr id="rIndex" onclick="popUserDetail(this)" onmousemove="hidePopUserDetail()">
                    <input type="hidden" name="customerId" value="'.$records["uniqueid"].'"> 
                    <input type="hidden" name="firstLogin" value="'.$records["firstLogin"].'"> 
                    <input type="hidden" name="address" value="'.$records["address"].'">                                    
                         <td width="40px">'.st($records['lastT'],$fileLastUploadTime).'</td>
                          <td width="100px">'.$records['barName'].'</td>
                          <td width="160px">'.$records['lastLogin'].'</td>
                          <td width="160px">'.date("Y-m-d H:i:s",$arr[1]).'</td>
                          <td width="150px">'.$records['endTM'].'</td>
                          <td width="40px">'.$arr[0].'</td>
                          <td width="40px" style="border-right:0;">'.$records['version'].'</td>
                          </tr>';
                  } 
 print                  '</table>
                    <div class="popUserDetail" id="popUserDetail">
                          <table>
                          <tr><td id="">客户编号:</td><td id="cId"></td></tr>                                          
                          <tr><td>客户地址:</td><td></td></tr>
                          <tr><td>初次登陆:</td><td>备份周期:</td></td></tr>
                          <tr><td>联系QQ:</td><td>联系电话:</td></td></tr>
                          </table>
                    </div>

登录后复制


------解决方案--------------------
看看你这句是什么?

 var customerId = document.getElementsByTagName("input")[0].value;

索引是0当然永远是第一个。

改为:
var customerId = document.getElementsByTagName("input")[x.rowIndex].value;

Try It Again!
------解决方案--------------------
var customerId = document.getElementsByTagName("input")[0].value;写错了
------解决方案--------------------
探讨

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号