<legend id='oze28'><style id='oze28'><dir id='oze28'><q id='oze28'></q></dir></style></legend>

<small id='oze28'></small><noframes id='oze28'>

      <bdo id='oze28'></bdo><ul id='oze28'></ul>

  • <tfoot id='oze28'></tfoot>

  • <i id='oze28'><tr id='oze28'><dt id='oze28'><q id='oze28'><span id='oze28'><b id='oze28'><form id='oze28'><ins id='oze28'></ins><ul id='oze28'></ul><sub id='oze28'></sub></form><legend id='oze28'></legend><bdo id='oze28'><pre id='oze28'><center id='oze28'></center></pre></bdo></b><th id='oze28'></th></span></q></dt></tr></i><div id='oze28'><tfoot id='oze28'></tfoot><dl id='oze28'><fieldset id='oze28'></fieldset></dl></div>

      1. 如何用 Javascript 替换和追加

        How to replace and append with Javascript(如何用 Javascript 替换和追加)
        <legend id='ddEIC'><style id='ddEIC'><dir id='ddEIC'><q id='ddEIC'></q></dir></style></legend>

            <tbody id='ddEIC'></tbody>
          • <i id='ddEIC'><tr id='ddEIC'><dt id='ddEIC'><q id='ddEIC'><span id='ddEIC'><b id='ddEIC'><form id='ddEIC'><ins id='ddEIC'></ins><ul id='ddEIC'></ul><sub id='ddEIC'></sub></form><legend id='ddEIC'></legend><bdo id='ddEIC'><pre id='ddEIC'><center id='ddEIC'></center></pre></bdo></b><th id='ddEIC'></th></span></q></dt></tr></i><div id='ddEIC'><tfoot id='ddEIC'></tfoot><dl id='ddEIC'><fieldset id='ddEIC'></fieldset></dl></div>

              <small id='ddEIC'></small><noframes id='ddEIC'>

              • <tfoot id='ddEIC'></tfoot>

                • <bdo id='ddEIC'></bdo><ul id='ddEIC'></ul>
                  本文介绍了如何用 Javascript 替换和追加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个评论系统,我想在其中实现内联编辑(当有人知道一个好的插件或类似的东西时,请不要犹豫给我一个名字)并找到一个用 textarea 替换文本的 Javascript 片段并将文本作为该文本区域的值.

                  I have a comment system in which I want to realize inline-editing (when someone knows a good plugin or something similar please don't hesitate to give me a name) and found a Javascript snippet which replaces the text with a textarea and the text as the value of that textarea.

                  但现在我需要向该文本区域添加一个按钮(提交按钮),以便用户可以保存他编辑的文本.

                  But now I need to add a button (submit button) to that textarea so that the user could save the text he edited.

                  我的代码现在看起来像

                  <span id="name">comment</span>
                  
                  <div onclick="replacetext();">test</div>
                  
                  <script type="text/javascript">
                      function replacetext(){
                              $("#name").replaceWith($('<textarea>').attr({ id: 'name', value: $('#name').text() }));
                      </script>
                  

                  我已经用 $("#name").append('<button>yes</button>'); 对其进行了测试,但没有成功.

                  I've tested it out with $("#name").append('<button>yes</button>'); but it didn't work.

                  推荐答案

                  可以使用下面的 jsFiddle 试用解决方案:http://jsfiddle.net/adb8X/5/

                  The solution can be tried out using the following jsFiddle: http://jsfiddle.net/adb8X/5/

                  我相信你追求的是:

                    $('<button>yes</button>').insertAfter("#name");
                  

                  上面的代码在目标选择器(#name")中具有指定 id 的 DOM 元素之后插入一个新创建的 DOM 元素(是).

                  The code above inserts a newly created DOM element (yes) right after the DOM element with the specified id in the target selector ("#name").

                  更多关于 insertAfter 的信息在这里:http://api.jquery.com/插入后/

                  More about insertAfter here: http://api.jquery.com/insertAfter/

                  如果要插入到replacetext()中,会变成:

                  If you want to insert it into replacetext(), it will become:

                  function replacetext() {
                      $("#name").replaceWith($('<textarea>').attr({
                          id: 'name',
                          value: $('#name').text()
                      }));
                  
                      $('<button>yes</button>').insertAfter("#name");
                  
                  } 
                  

                  <小时>

                  注意:我还更正了您的 jsFiddle.请在此处查看:http://jsfiddle.net/adb8X/5/(存在问题如果我没记错的话,设置和一个小错字).其中对应的行是:


                  Note: I also corrected your jsFiddle. Please check here: http://jsfiddle.net/adb8X/5/ (There were problems with the settings and a small typo if I recall correctly). The corresponding line in that is:

                   $("#name").append( $('<button>hi</button>') );
                  

                  这篇关于如何用 Javascript 替换和追加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Toggle HTML radio button by clicking its label(通过单击标签来切换 HTML 单选按钮)
                  Javascript how to change radio button label text?(Javascript如何更改单选按钮标签文本?)
                  JavaScript radio button confirmation(JavaScript 单选按钮确认)
                  How can I automatically select specific radio buttons with Greasemonkey?(如何使用 Greasemonkey 自动选择特定的单选按钮?)
                  AngularJs. Is it possible to deselect HTML “radio” input by click?(AngularJs.是否可以通过单击取消选择 HTML“收音机输入?)
                  Checking Value of Radio Button Group via JavaScript?(通过 JavaScript 检查单选按钮组的值?)

                  <tfoot id='Qtszt'></tfoot>
                      <tbody id='Qtszt'></tbody>
                    <legend id='Qtszt'><style id='Qtszt'><dir id='Qtszt'><q id='Qtszt'></q></dir></style></legend>

                    <small id='Qtszt'></small><noframes id='Qtszt'>

                        <i id='Qtszt'><tr id='Qtszt'><dt id='Qtszt'><q id='Qtszt'><span id='Qtszt'><b id='Qtszt'><form id='Qtszt'><ins id='Qtszt'></ins><ul id='Qtszt'></ul><sub id='Qtszt'></sub></form><legend id='Qtszt'></legend><bdo id='Qtszt'><pre id='Qtszt'><center id='Qtszt'></center></pre></bdo></b><th id='Qtszt'></th></span></q></dt></tr></i><div id='Qtszt'><tfoot id='Qtszt'></tfoot><dl id='Qtszt'><fieldset id='Qtszt'></fieldset></dl></div>
                          <bdo id='Qtszt'></bdo><ul id='Qtszt'></ul>