如何通过将值从第一行传递到下一行来对数组进行排序

时间:2017-09-07 01:52:28

标签: javascript jquery html

根据下图显示开始日期和结束日期。流程是这样的:

  1. 用户点击生成按钮以计算结束日期
  2. 用户点击生成按钮后,我希望第一行中完成文本框的结束日期显示在开始文本框的第二行。
  3. 在将值传递给start之后,用户再次单击第二行的“生成”按钮,它将进行计算,并且将与下一行完成相同的操作。
  4. 观点:

    The view

    以下是代码: JAVASCRIPT

    function getDate(id) {
        id = id.match(/\d+/);
    
        var sd = document.getElementById('start_date'+ id).value;
        //var fd = document.getelementById('firstdate'+ id).value;
         //var ed = document.getElementById('end_date'+ id).value;
        var d = document.getElementById('duration' + id).value;        
        var m = document.getElementById('marking' + id).value;
    
        var date = new Date(sd);
        var newdate = new Date(date);
        var durations = parseInt(d);
        var markings = parseInt(m);
    
    
        if ( markings == 0 || markings == 1 )
        {
            newdate.setDate(newdate.getDate());
    
        }
        else if ( markings == 2 )
        {
             newdate.setDate((newdate.getDate() + durations)-1);
        }
        else if ( markings == 3 )
        {
             newdate.setDate(newdate.getDate() + durations);
        }
    
    
        //newdate.setDate((newdate.getDate() + durations)-1);
    
        var dd = newdate.getDate();
        var mm = newdate.getMonth()+1;
        var y = newdate.getFullYear();
    
        var someFormattedDate = y + '-' + mm + '-' + dd;
        document.getElementById('end_date' + id).value = someFormattedDate;
    

    HTML

    <td style="font-family:century-gothic">
    
            <font color="black">Bina Stor</font>
        </td>
    
        <td>
          <input type="text" id="task_mark1" class="task_mark" name="task_mark" value="T1" />
        </td>
    
        <td>
          <input type="text"  id="marking1" class="marking" name="marking" value="0" />
        </td>
    
        <td>
          <input type="text" id="destination_marking1" class="destination_marking" name="destination_marking" value="0" />
        </td>
    
        <td>
          <input type="text" id="days1" class="days" name="days" value="0" />
        </td>
    
        <td>
          <input type="text" id="duration1" class="duration" name="duration" value="1" />
        </td>
    
        <td>
          <input type="text" id="start_date1" class="start_date" name="start_date" value="2017-02-02" />
        </td>
    
        <td>
          <input type="text" id="end_date1" class="end_date" name="end_date" value="" />
        </td>
    
        <td align="center">
    
          <input type="button" id ="btn1" value="GENERATE" name="action" class ="submit-green" onclick="getDate(this.id)"/>
    
        </td>
    
        </tr>
    
         <tr>
         <td></td>
        <td></td>
         <td style="font-family:century-gothic" >
    
            <font color="black">Side Rail</font>
        </td>
         <td>
          <input type="text" id="task_mark2" class="task_mark" name="task_mark" value="T2" />
        </td>
    
        <td>
          <input type="text"  id="marking2" class="marking" name="marking" value="3" />
        </td>
    
        <td>
          <input type="text" id="destination_marking2" class="destination_marking" name="destination_marking" value="0" />
        </td>
    
        <td>
          <input type="text" id="days2" class="days" name="days" value="0" />
        </td>
    
        <td>
          <input type="text" id="duration2" class="duration" name="duration" value="1" />
        </td>
    
        <td>
          <input type="text" id="start_date2" class="start_date" name="start_date" value="" />
        </td>
    
        <td>
          <input type="text" id="end_date2" class="end_date" name="end_date" value="" />
        </td>
    
        <td align="center">
    
          <input type="button" id ="btn2" value="GENERATE" name="action" class ="submit-green" onclick="getDate(this.id)"/>
    
        </td>
    
        </tr>
    

0 个答案:

没有答案