有人知道为什么当我单击粗体按钮时页面会重新加载吗?
因为当我想将文本设为粗体并单击按钮时,页面会自动重新加载
$('#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>
答案 0 :(得分:0)
将按钮上的类型设置为“按钮”。它可能默认为“提交”
<button id='bold_btn' type='button' class="btn btn-outline-secondary">
<b>B</b>
</button>