简体   繁体   English

防止按钮重置文本框值

[英]prevent button to reset textbox value

I am trying to create mcq question and able to add the question. 我正在尝试创建mcq问题并能够添加问题。 but the problem appear when i already fill the textbox and when i press the add question button, the textbox value always disappear. 但是当我已经填满文本框并按下添加问题按钮时,问题就会出现,文本框值始终消失。

<form name="newdocument">

            <div id="questions" data-role="fieldcontain"><input type="text" value="dsa"/></div>
            <input type="button" value="Add Question" onclick="AddQuestion();" />

        </form>

the javascript code is on http://jsfiddle.net/Xv3Xq/1/ javascript代码位于http://jsfiddle.net/Xv3Xq/1/

Dont use innerHtml+= , its bad . 不要使用innerHtml+=这是不好的 The stuff you write in an input field will get erased, since its not considered when using innerHtml but rather erased. 您在输入字段中编写的内容将被删除,因为在使用innerHtml时不会考虑它,而是将其删除。 Use jQuery! 使用jQuery! Something like: 就像是:

$('#addQuestion').click(function() {
  $('<input />').appendTo($('#questions'));
});

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

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