Home Web Front-end HTML Tutorial How to achieve the effect of clicking the button text to become an input box, and clicking save to turn it into text.

How to achieve the effect of clicking the button text to become an input box, and clicking save to turn it into text.

Jan 23, 2018 am 10:47 AM
button letter Click

This time I will show you how to realize the effect of turning the text of a click button into an input box, and click save to turn it into text. What are the precautions for realizing the effect of turning the text of a click button into an input box, and clicking save to turn it into text? , the following is a practical case, let’s take a look.

<!DOCTYPE html>  
<html lang="en">  
<head>  
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
  <meta charset="utf-8">  
  <title>点击按钮文字变成input框,点击保存变成文字</title>  
  <style type="text/css">  
  table{ text-align: center; font-size: 14px;}   
  table>thead>tr>th{ font-weight: normal;}   
  .text-right{ padding-right:73px; text-align: right;}   
  .text{ width: 50px; height: 30px; border: 1px solid #ddd; text-align: center;}   
  </style>  
  <script type="text/javascript" src="js/jquery.min.js"></script>  
</head>  
  
<body>  
  <table>  
    <thead>  
      <tr>  
        <th width="400">品名</th>  
        <th width="200">件数</th>  
      </tr>  
    </thead>  
    <tbody>  
      <tr height="50">  
        <td>iPhone6s</td>  
        <td class="edit">2</td>  
      </tr>  
      <tr height="50">  
        <td>小米5</td>  
        <td class="edit">5</td>  
      </tr>  
    </tbody>  
    <tfoot>  
      <tr>  
        <td colspan="2" class="text-right">  
          <button type="button" class="btn" onclick="change(this)">修改</button>  
        </td>  
      </tr>  
    </tfoot>  
  </table>  
  
<script type="text/javascript">  
function change(obj){   
  var xg=$(obj).html();   
  if(xg==&#39;修改&#39;){   
    $(&#39;.edit&#39;).each(function(){   
      var old=$(this).html();   
      $(this).html("<input type=&#39;text&#39; name=&#39;editname&#39; class=&#39;text&#39; value="+old+" >");   
    })   
    $(obj).html(&#39;保存&#39;);   
  }else if(xg==&#39;保存&#39;){   
    $(&#39;input[name=editname]&#39;).each(function(){   
      var old=$(this).html();   
      var newfont=$(this).parent(&#39;td&#39;).parent(&#39;tr&#39;).children().find(&#39;input&#39;).val();   
      $(this).parent(&#39;td&#39;).html(newfont);   
    })   
    $(obj).html(&#39;修改&#39;);   
  }   
}   
</script>  
  
  
  
</body>  
</html>
Copy after login

I believe you have mastered the methods after reading these cases. For more exciting information, please pay attention to other related articles on the php Chinese website!

Related reading:

How to make mobile web page content adaptive

How to deal with content overflow in the table table

htmlImportant knowledge points you must know about PHP

The above is the detailed content of How to achieve the effect of clicking the button text to become an input box, and clicking save to turn it into text.. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

5 Ways to Disable Delivery Optimization Service in Windows 5 Ways to Disable Delivery Optimization Service in Windows May 17, 2023 am 09:31 AM

There are many reasons why you might want to disable the Delivery Optimization service on your Windows computer. However, our readers complained about not knowing the correct steps to follow. This guide discusses how to disable the Delivery Optimization service in a few steps. To learn more about services, you may want to check out our How to open services.msc guide for more information. What does Delivery Optimization Service do? Delivery Optimization Service is an HTTP downloader with cloud hosting solution. It allows Windows devices to download Windows updates, upgrades, applications and other large package files from alternative sources. Additionally, it helps reduce bandwidth consumption by allowing multiple devices in a deployment to download these packages. In addition, Windo

How to make round pictures and text in ppt How to make round pictures and text in ppt Mar 26, 2024 am 10:23 AM

First, draw a circle in PPT, then insert a text box and enter text content. Finally, set the fill and outline of the text box to None to complete the production of circular pictures and text.

How to restart, force restart, and shut down iPad Mini 6 How to restart, force restart, and shut down iPad Mini 6 Apr 29, 2023 pm 12:19 PM

How to Force Restart iPad Mini 6 Force restarting iPad Mini 6 is done with a series of button presses, and it works like this: Press and release for Volume Up Press and release for Volume Down Press and release the Power/Lock button until you see Apple logo, indicating that the iPad Mini has been force restarted. That’s it. You have force restarted the iPad Mini 6! Force restart is usually used for troubleshooting reasons, such as the iPad Mini freezing, apps freezing, or some other general misbehavior. One thing to note about the procedure for force restarting the 6th generation iPad Mini is that for all other devices that have ultra-thin bezels and use

After rewriting:

How to Fix PS5 Controller Not Recognized on Windows 11 After rewriting: How to Fix PS5 Controller Not Recognized on Windows 11 May 09, 2023 pm 10:16 PM

&lt;h3&gt;What should I know about connecting my PS5 controller? &lt;/h3&gt;&lt;p&gt;As good as the DualSense controller is, there have been reports of the controller not connecting or not being detected. The easiest way to solve this problem is to connect the controller to your PC using an appropriate USB cable. &lt;/p&gt;&lt;p&gt;Some games natively support DualSense. In these cases, you can simply plug in the controller. But this raises other questions, like what if you don't have a USB cable or don't want to use one

How to add dots to text in word? How to add dots to text in word? Mar 19, 2024 pm 08:04 PM

When we create Word documents on a daily basis, we sometimes need to add dots under certain words in the document, especially when there are test questions. To highlight this part of the content, the editor will share with you the tips on how to add dots to text in Word. I hope it can help you. 1. Open a blank word document. 2. For example, add dots under the words &quot;How to add dots to text&quot;. 3. We first select the words &quot;How to add dots to text&quot; with the left mouse button. Note that if you want to add dots to that word in the future, you must first use the left button of the mouse to select which word. Today we are adding dots to these words, so we have chosen several words. Select these words, right-click, and click Font in the pop-up function box. 4. Then something like this will appear

How to set multiple timers on iPhone iOS 17 How to set multiple timers on iPhone iOS 17 Sep 18, 2023 am 09:01 AM

In iOS 17, you can set multiple timers on your iPhone using the Clock app, or use Siri to set it hands-free. We discuss both in this article. Let's take a look at them. Set Multiple Timers on iPhone Using the Clock App Open the Clock app on your iPhone and tap the Timers tab in the lower right corner. Now, set the hours, minutes, and seconds. You can use the "Label" and "When does the timer end" options to set a name for the timer and a preferred tone when the timer completes. This will help you differentiate between timers. Once done, click the "Start" button. Then, click the "+" icon in the upper right corner. Now, repeat the above steps to set multiple timers on iPhone. You can also browse

How to clear the download history of Microsoft Edge browser? How to clear the download history of Microsoft Edge browser? Apr 21, 2023 am 09:34 AM

&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Click to enter:&lt;/strong&gt;ChatGPT tool plug-in navigation&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;Find and delete download history in Edge&lt; /h2&gt;&lt;p&gt;Like other browsers, Edge has a&lt;strong&gt;Download

Change the power button action on Windows 11 [5 Tips] Change the power button action on Windows 11 [5 Tips] Sep 29, 2023 pm 11:29 PM

The power button can do more than shut down your PC, although this is the default action for desktop users. If you want to change the power button action in Windows 11, it's easier than you think! Keep in mind that the physical power button is different from the button in the Start menu, and the changes below won't affect the operation of the latter. Additionally, you'll find slightly different power options depending on whether it's a desktop or laptop. Why should you change the power button action in Windows 11? If you put your computer to sleep more often than you shut it down, changing the way your hardware power button (that is, the physical power button on your PC) behaves will do the trick. The same idea applies to sleep mode or simply turning off the display. Change Windows 11

See all articles