这个JQuery可编辑内容代码有什么解决方案

时间:2019-08-08 13:46:14

标签: javascript jquery

我正在处理一个毕业网站项目,并且希望使文本可编辑。我尝试了此jQuery代码,但对我而言不起作用。

我正在使用Bootstrap CSS和jQuery。当我添加其他JS或jQuery代码时,它对我就不起作用了。

cnsdns是我在构建网站时使用的

// that's what i use like cdns in my website//
<!--bootsrap script-->

<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<!--end bootsrap script-->

<!--MDBOOTSTRAP script LINKS-->

<!-- JQuery -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- Bootstrap tooltips -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.4/umd/popper.min.js"></script>
<!-- Bootstrap core JavaScript -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
<!-- MDB core JavaScript -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mdbootstrap/4.7.5/js/mdb.min.js"></script>
 <!--MDBOOTSTRAP scriptLINKS end-->

////

$('.edit').click(function() {
  $(this).hide();
  $('.box').addClass('editable');
  $('.text').attr('contenteditable', 'true');
  $('.save').show();
});

$('.save').click(function() {
  $(this).hide();
  $('.box').removeClass('editable');
  $('.text').removeAttr('contenteditable');
  $('.edit').show();
});
.box {
  position: absolute;
  left: 40%;
  top: -6%;
  width: 400px;
  min-height: 150px;
  border: 1px solid grey;
  border-radius: 3px;
  background: #fff;
}

.editable {
  border-color: #bd0f18;
  box-shadow: inset 0 0 10px #555;
  background: #f2f2f2;
}

.edit,
.save {
  width: 60px;
  display: block;
  position: absolute;
  top: 0px;
  right: 0px;
  padding: 4px 10px;
  border-top-right-radius: 2px;
  border-bottom-left-radius: 10px;
  text-align: center;
  cursor: pointer;
  box-shadow: -1px 1px 4px rgba(0, 0, 0, 0.5);
}

.edit {
  background: #557a11;
  color: #f0f0f0;
  opacity: 0;
  transition: opacity .2s ease-in-out;
}

.save {
  display: none;
  background: #bd0f18;
  color: #f0f0f0;
}

.box:hover .edit {
  opacity: 1;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="col-lg-7 pl box">
  <span class="edit">edit</span>
  <span class="save">save</span>
  <div class="text">
    <h3 class="font-weight-bold mb-3"></h3>
    <strong>Dépôt A</strong>
    </h3>
    <p><strong>Type des produits :alimentaire </strong></p>
    <p><strong>Dernière modification:12/02/2019 </strong></p>
    <p><strong>Situation:50% </strong></p>
    <a href="details.html" target="_self" class="btn btn-black btn-success btn-md">vérifier</a>
  </div>
</div>

我希望它给出以下结果:https://codepen.io/gab/pen/dJmIE

0 个答案:

没有答案