简体   繁体   中英

does anybody know why the pagina reloads

Does anybody know why the page reloads when i click on the bold button?

Because when i want to make a text bold and click on the button, the page reloads automatically

  $('#bold_btn').on('click', function () { document.execCommand('bold'); var text = document.getElementById('textarea').innerHTML; $('#textarea-show').html(text); }); $('#italic_btn').on('click', function () { document.execCommand('italic'); var text = document.getElementById('textarea').innerHTML; $('#textarea-show').html(text); }); console.log() $('.saveBtn').click(function(event) { event.preventDefault(); let data = $( "div#textarea" ).html(); $('textarea#answerstextarea').html(data); $('#question-create-form').submit(); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <button id='bold_btn' class="btn btn-outline-secondary"><b>B</b></button> <button id='italic_btn'class="btn btn-outline-secondary"><i>I</i></button> <div contenteditable="true" id="textarea" name="answers" class="form-control">{{ old('answers',$task->description) }}</div> <textarea name="answers" id="answerstextarea"></textarea> 

Set the type on the button to 'button'. It may be defaulting to 'submit'

<button id='bold_btn' type='button' class="btn btn-outline-secondary">
  <b>B</b>
</button>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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