惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

雷峰网
雷峰网
爱范儿
爱范儿
宝玉的分享
宝玉的分享
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - Franky
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 三生石上(FineUI控件)
人人都是产品经理
人人都是产品经理
阮一峰的网络日志
阮一峰的网络日志
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Last Week in AI
Last Week in AI
博客园 - 聂微东
大猫的无限游戏
大猫的无限游戏
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
罗磊的独立博客
博客园 - 叶小钗
WordPress大学
WordPress大学
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
酷 壳 – CoolShell
酷 壳 – CoolShell
小众软件
小众软件
博客园 - 司徒正美
博客园 - 【当耐特】
IT之家
IT之家

博客园 - lgzh

spring boot 调用python ,研发环境下AttributeError: module 'clip' has no attribute 'load' el-tree选中背景变色 jquery datatable分页 png 变透明 Code First 不自动生成数据库 读取文件不是真实的具体路径 setZh.ini win10 开发mfc 64位 ocx控件 win7 下加载MSCOMCTL.OCX getGLES1ExtensionString: Could not find GLES 1.x config! IUnknown(TVarData(Params[0]).VPointer) as Range win8 VB6打开提示MSCOMCTL.ocx未注册 SQL Server 自定义函数 返回树结构函数 .net 安装包制作 大图 预览 android 创建数字签名应用程序 android java.net.socketexception permission denied an error occurred while signing: '.', hexadecimal value 0x00, is an invalid character IIS配置、403.6 无权查看,网页拒绝访问 C#后台调用Delphi 的Ocx
js 动态添加行,删除行,并获得select中值赋予 input
lgzh · 2013-06-20 · via 博客园 - lgzh

<html>
 <head>
  <title>Ace Test</title>
  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script>

<script language="JavaScript">   
  var cGetRow=-99999;
  function insertrow(){
  var newrow = document.all.newTB.rows[0].cloneNode(true); //克隆一行
  document.all("newTB").appendChild(newrow); //添加刚才克隆的一行
   var objs = document.getElementsByName("project1");
 
 objs[objs.length-1].value=""; 
 
 
  }
   

  function GetRow(){
 //获得行索引
 //两个parentElement分别是TD和TR,rowIndex是TR的属性
 //this.parentElement.parentElement.rowIndex
    cGetRow=window.event.srcElement.parentElement.parentElement.rowIndex;
   
    DelRow(cGetRow);//点击checkbox时,直接删除行。
  }
  function DelRow(iIndex){
 //删除一行
 if(iIndex==-99999){
   alert("系统提示:没有选中行号!");
 }else{
   newTB.deleteRow(iIndex);
   iIndex==-99999;//将rowIndex恢复默认值。
 }
  }
 
  function GetPidValue(st){
  // var chooseVal = st.innerText;
 //alert("选择的值是:" + chooseVal); 
 //$("#result").val("Hello world!");
 
    cGetRow=window.event.srcElement.parentElement.parentElement.rowIndex;
 
 
 var tableInfo = "";  
 var tableObj = document.getElementById("newTB"); 
 //alert( tableObj.rows[cGetRow].cells.length)
 
 var Cell=tableObj.rows[cGetRow].cells[1].innerHTML
 
 var b=document.getElementsByName('project')[cGetRow];//这里也可以用getElementById
 var selectValue;
 for(var i=0;i<b.length;i++){
  if(b[i].selected==true){
   selectValue=b[i].innerText;
  }
 }
 
  
 var objs = document.getElementsByName("project1");
 objs[cGetRow].value=selectValue; 
 
 
 
   
  }
 
  </script>
 </head>

 <body class="dialog_body">
  <form method="POST" onSubmit="return   doSubmit(this)">
 
   
     <table border="1" width="900" cellpadding="0" cellspacing="0" class="table">
    
      <!-- 隐藏table,用于克隆的行 begin -->
      <tbody id="ACE_HIDDEN_TABLE" >
      
      </tbody>
     </table>
     <!-- 隐藏table,用于克隆的行 end -->
    
     <table border="1" width="900" cellpadding="0" cellspacing="0" class="table">
      <!-- 插入新行的区域 begin -->
      <tbody id="newTB">
    <tr>
       
        <td width="16%">
         <select id="pid" name="project"" onchange="GetPidValue(this)">
          <option value=""></option>
          <option value="0">
           人员编号
          </option>
          <option value="1">
           姓名
          </option>
         </select>
        </td>
        <td width="16%">
         <input id="result" name="project1" type="text" value="" >
        </td>
  <td><input type="button"  value="删除" onClick="GetRow()"/></td>
       </tr>
      </tbody>
      <!-- 插入新行的区域 end -->
     </table>

   <div align="right" style="margin:10px;"> 
    <input type="button" onClick="insertrow();" value="增加一行">
    <input type="button" onClick="DelRow(cGetRow);" value="删除一行">
   </div>
  
  </form>
 </body>
</html>