添加 div javascript,然后在 jquery 中就地编辑



我已经使用 JavaScript 在div 中使用了 Add/Remove HTML 中的代码来使其满足我的需求,但无法使用我找到的任何就地编辑脚本进行任何添加<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>

相关内容

  • 没有找到相关文章

最新更新