添加 div javascript 然后就地编辑 jquery

Add div javascript and then edit in place jquery

我已使用 Add/remove HTML inside div using JavaScript 中的代码使其满足我的需要,但无法使用任何就地编辑脚本使任何添加的 <div><span> 可编辑我找到了。

如您所见,最后一个可编辑字段工作正常,但添加了“+”的任何新字段都不起作用。

我们将不胜感激。

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://wosephjeber.com/inputizer/dist/inputizer.js"></script>
   
<script>function counter(){return( $(".border").length );}</script>
<input type="button" value="+" onclick="addRow()">
<div id="content">
</div>
<span class="border">1</span>
<span class="border">2</span>
<span class="border">3</span>
<span class="border">4</span>


<script type="text/javascript">
function addRow() {
    var count =$(".border").length+1;
    var div = document.createElement('div');

    div.className = 'border';
    div.innerHTML = '<span class="icounter">'+ count +'</span> <span class="inputize-me">This is editable</span> <span id="Display" class="ir"></span>\
        <input type="button" value="-" onclick="removeRow(this)">';

     document.getElementById('content').appendChild(div);
}

function removeRow(input) {
    document.getElementById('content').removeChild( input.parentNode );
}

</script>
<br><br>
<span class="inputize-me">This is editable</span>
 <script>
      $('.inputize-me').inputizer(function(value) {
        console.log(value);
      });
    </script>

只需将 contenteditable="true" 添加到可编辑元素

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://wosephjeber.com/inputizer/dist/inputizer.js"></script>
   
<script>function counter(){return( $(".border").length );}</script>
<input type="button" value="+" onclick="addRow()">
<div id="content">
</div>
<span class="border">1</span>
<span class="border">2</span>
<span class="border">3</span>
<span class="border">4</span>


<script type="text/javascript">
function addRow() {
    var count =$(".border").length+1;
    var div = document.createElement('div');

    div.className = 'border';
    div.innerHTML = '<span class="icounter">'+ count +'</span> <span class="inputize-me" contenteditable="true">This is editable</span> <span id="Display" class="ir"></span>\
        <input type="button" value="-" onclick="removeRow(this)">';

     document.getElementById('content').appendChild(div);
}

function removeRow(input) {
    document.getElementById('content').removeChild( input.parentNode );
}

</script>
<br><br>
<span class="inputize-me" contenteditable="true">This is editable</span>
 <script>
      $('.inputize-me').inputizer(function(value) {
        console.log(value);
      });
    </script>