簡體   English   中英

我如何將文本更改為單擊文本本身的輸入字段

[英]How can I change text to input field clicking on the text itself

當我單擊承諾時,我想更改承諾文本以在輸入字段中進行更改,當我按Enter鍵時,它應該顯示新輸入的輸入。

我是Java語言的新手,但是我看了很多代碼,但是他們沒有滿足我的要求,請您提供如何執行此操作的任何想法?

<div class="table-responsive">
    <table class="table table-bordered table-hover" id="dtBasicExample" cellspacing="0" width="100%">
      <!-- Table head -->
      <thead class="theader">
        <tr>
          <th>Grade</th>
          <th>Student</th>
          <th>
            <!-- Default un -->
            <!-- <div class="custom-control custom-checkbox">
              <input type="checkbox" class="custom-control-input" id="tableDefaultCheck1">
              <label class="custom-control-label" for="tableDefaultCheck1">P/A</label>
            </div> -->P/A
          </th>
          <th>Check-In</th>
          <th>Check-Out</th>
          <th>Tutor</th>
          <th>Videos</th>
          <th>Others</th>
          <th>Commitment</th>
        </tr>
      </thead>
<tbody>
</tr>
        <tr>
          <td>7</td>
          <td>Name</td>
          <th scope="row">
            <!-- Default un -->
            <div class="custom-control custom-checkbox">
              <input type="checkbox" class="custom-control-input" id="tableDefaultCheck3">
              <label class="custom-control-label" for="tableDefaultCheck3"></label>
            </div>
          </th>
          <td>Time</td>
          <td>Time</td>
          <td>Time</td>
          <td>Time</td>
          <td>Time</td>
          <td>Commitment
            <div class="md-form">
              <input type="text" id="form2" class="form-control">
              <label for="form2">New Commitment</label>
            </div>
          </td>
        </tr>
</tbody>
</table>

這是你想要的?

$('.md-form input').keydown(function(e) {
  if(e.keyCode == 13 && $(this).val().length > 0){
    $(this).next().text($(this).val())
  }
});

工作演示

 $('.md-form input').keydown(function(e) { if (e.keyCode == 13 && $(this).val().length > 0) { $(this).next().show().text($(this).val()) $(this).hide(); } }); $('.Commitment label').click(function() { $(this).prev().show(); $(this).hide(); }) 
 .Commitment input { display: none; } 
 <script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script> <div class="table-responsive"> <table class="table table-bordered table-hover" id="dtBasicExample" cellspacing="0" width="100%"> <!-- Table head --> <thead class="theader"> <tr> <th>Grade</th> <th>Student</th> <th> <!-- Default un --> <!-- <div class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input" id="tableDefaultCheck1"> <label class="custom-control-label" for="tableDefaultCheck1">P/A</label> </div> -->P/A </th> <th>Check-In</th> <th>Check-Out</th> <th>Tutor</th> <th>Videos</th> <th>Others</th> <th>Commitment</th> </tr> </thead> <tbody> <tr> <td>7</td> <td>Name</td> <th scope="row"> <!-- Default un --> <div class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input" id="tableDefaultCheck3"> <label class="custom-control-label" for="tableDefaultCheck3"></label> </div> </th> <td>Time</td> <td>Time</td> <td>Time</td> <td>Time</td> <td>Time</td> <td class="Commitment"> <div class="md-form"> <input type="text" id="form2" class="form-control"> <label for="form2">New Commitment</label> </div> </td> </tr> <tr> <td>7</td> <td>Name</td> <th scope="row"> <!-- Default un --> <div class="custom-control custom-checkbox"> <input type="checkbox" class="custom-control-input" id="tableDefaultCheck3"> <label class="custom-control-label" for="tableDefaultCheck3"></label> </div> </th> <td>Time</td> <td>Time</td> <td>Time</td> <td>Time</td> <td>Time</td> <td class="Commitment"> <div class="md-form"> <input type="text" id="form2" class="form-control"> <label for="form2">New Commitment</label> </div> </td> </tr> </tbody> </table> </div> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM