2013-12-20 40 views
0
<script type="text/javascript"> 


$(document).ready(function(){ 

var count=$('#option1').val(); 
var counter = 1; 

$("#addButton").click(function() { 

if(counter>count){ 
     alert("Only "+count+" textboxes allow"); 
     return false; 
} 

var newTextBoxDiv = $(document.createElement('div')) 
    .attr("id", 'TextBoxDiv' + counter); 

newTextBoxDiv.after().html('<input type="radio" name="answer" id="answer" value="' + counter + '" /><label>Option #'+ counter + ' : </label>' + 
     '<textarea name="textbox' + counter + 
     '" id="textbox' + counter + '" value="" />'); 

newTextBoxDiv.appendTo("#TextBoxesGroup"); 

tinymce.init({ 
     selector: "textarea", 
     force_p_newlines : false, 


    plugins: [ 
      "advlist autolink autosave image link lists charmap print preview hr anchor pagebreak spellchecker", 
      "searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking", 
      "table contextmenu directionality emoticons template textcolor paste fullpage textcolor" 
    ], 

    toolbar1: "newdocument fullpage | bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | styleselect formatselect fontselect fontsizeselect | cut copy paste | searchreplace | bullist numlist | outdent indent blockquote | undo redo | link unlink anchor image media | inserttime preview ", 
    toolbar2: "forecolor backcolor | table | hr removeformat | subscript superscript | charmap emoticons | print fullscreen | ltr rtl | spellchecker | visualchars visualblocks nonbreaking template pagebreak restoredraft ", 

    image_advtab: true, 
    menubar: false, 
    toolbar_items_size: 'small', 

    style_formats: [ 
      {title: 'Bold text', inline: 'b'}, 
      {title: 'Red text', inline: 'span', styles: {color: '#ff0000'}}, 
      {title: 'Red header', block: 'h1', styles: {color: '#ff0000'}}, 
      {title: 'Example 1', inline: 'span', classes: 'example1'}, 
      {title: 'Example 2', inline: 'span', classes: 'example2'}, 
      {title: 'Table styles'}, 
      {title: 'Table row 1', selector: 'tr', classes: 'tablerow1'} 
     ], 

     templates: [ 
       {title: 'Test template 1', content: 'Test 1'}, 
       {title: 'Test template 2', content: 'Test 2'} 
     ] 

}); 
//add tinymce to this 
tinyMCE.execCommand("mceAddControl", false, 'txt'+counter); 

    counter++; 
}); 

</script> 




<form method="post" name="myForm" id="form" action="upload" onsubmit="return validateForm()" > 
<div id='TextBoxesGroup'> 
    <div id="TextBoxDiv0"> 
     <label>Selection: </label><select name="sel" id="sel" > 
      <option selected="true" style="display:none;">Select </option> 
<% 
    ResultSet rsta1=st.executeQuery("SELECT DISTINCT term FROM termwhere term not like 'null'"); 
    while(rsta1.next()) { 
     out.write("<option value=" + rsta1.getString("term") + ">" + rsta1.getString("term") + "</option>"); 
    } 
%> 
     <label>Question: </label><textarea id='textbox0' name="textbox0"></textarea> 
     <input type="hidden" name="option1" id="option1" value="<%=options21 %>"/> 
    </div> 
</div> 
<input type='button' value='Add Button' id='addButton' /> 
<input type='button' value='Remove Button' id='removeButton'/> 
<input type='submit' value='Submit'/> 
</form> 

我有一个Jquery,当我按下添加按钮时,会出现更多的文本区域。这工作正常,此页面的提交也起作用。当我下次回来时会出现问题。窗体保留了以前的数据

以前输入到textareas中的所有数据都会再次出现,相同的旧数据将填充到textareas中。 我应该怎么做,以便表单域是空的?

我得到的另外一个问题是当我添加新的文本字段数据被刷新到旧的数据。

当我在一个textarea中添加文本并按下添加按钮时,我输入的文本消失或出现前面的文本(我上面解释过的第一个问题)。类似地,当我再次按下添加按钮时,前面的2个文本框会得到清空或以前的文本出现。 这是怎么回事?

+0

它可能是一个浏览器缓存问题,虽然为了清空textarea,我们可以在$ rea('#textbox0')。val('');'上添加rea DY。 – KunJ

+0

有没有办法使用JSP清空缓存? –

+0

我在上面的脚本中添加了urll回答,但不起作用 –

回答

0

尝试添加自动完成=关闭表单上以防止浏览器保留的信息

查看 - >https://developer.mozilla.org/en-US/docs/Mozilla/How_to_Turn_Off_Form_Autocompletion

OR

空使用JavaScript形式

formObject.reset ()

+0

自动完成功能无效.. –

+0

也不起作用 –

+0

这很奇怪,因为它在我以前的所有项目。我建议您清空浏览器缓存并重新开始测试。它发生在我身上,缓存阻止了我看到实际发生的事情。 – happy