简体   繁体   English

如何让div作为输入

[英]how to make div act as a input

I set up a check boxes that will display a progress bar and show its current progress by its percentage.我设置了一个复选框,它将显示一个进度条并按百分比显示其当前进度。 how do I make the div tag act as an input to save the value into the database如何使 div 标签充当输入以将值保存到数据库中

I tried using it on the div and it display the percentage but when I tried it using an input it fails to show the percentage我尝试在 div 上使用它并显示百分比但是当我尝试使用输入时它无法显示百分比

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="progressbar-container">
  <div class="progressbar-bar"></div>
  <div class="progressbar-label"></div>
  <input type="" name="" id="percentage">
$(document).ready(function() {
  // get box count
  var count = 0;
  var checked = 0;

  function countBoxes() {
    count = $("input[type='checkbox']").length;
    console.log(count);
  }

  countBoxes();
  $(":checkbox").click(countBoxes);

  // count checks

  function countChecked() {
    checked = $("input:checked").length;

    var percentage = parseInt(((checked / count) * 100), 10);
    $(".progressbar-bar").progressbar({
      value: percentage
    });
    $(".progressbar-label").text(percentage + "%");
    $('#percentage').text(percentage + "%")
  }

  countChecked();
  $(":checkbox").click(countChecked);

您可以使用contenteditable属性,然后通过innerHTML获取值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM