[英]Button doesn't work inside the html form but it works outside
Hi there I need some help with this html form! 嗨,我需要一些有关此html表单的帮助! I'm making a bulletin board using summernote ( https://summernote.org/examples/ )
我正在使用summernote( https://summernote.org/examples/ )制作公告板
At first I made the button(save, edit) outside the form and it perfectly worked. 首先,我将按钮(保存,编辑)放置在表单外部,并且效果很好。
Clicking edit button shows the editor 单击编辑按钮显示编辑器
And the save button saves the change and hides the editor 保存按钮保存更改并隐藏编辑器
However as I moved it inside it wouldn't work. 但是,当我将其移入内部时,它将无法工作。 Can't figure out why... Are the elements inside the form independent from the rest?
无法弄清楚为什么...表单中的元素是否独立于其余元素?
If not, what did I do wrong? 如果没有,我做错了什么? And what should I change to make two buttons exist inside the editor form?
我应该怎么做才能使两个按钮存在于编辑器表单中?
Html that works : 有效的HTML:
<div class="container">
<div class="page-header">
<h1>Hello</h1>
</div>
<form class="edit-summit-form" method="post" action=" ">
<div id="editor">
</div>
</form>
<p>
<!--<div id="summernote-result"></div>-->
</p>
<button id="edit" class="btn btn-primary" onclick="edit()" type="button">Edit 1</button>
<button id="save" class="btn btn-primary" onclick="save()" type="button">Save 2</button>
<div class="click2edit">click2edit</div>
</div>
Html that doesn't work : 无效的HTML:
<div class="container">
<div class="page-header">
<h1>Hello</h1>
</div>
<form class="edit-summit-form" method="post" action=" ">
<div id="editor">
<button id="edit" class="btn btn-primary" onclick="edit()" type="button">Edit 1</button>
<button id="save" class="btn btn-primary" onclick="save()" type="button">Save 2</button>
<div class="click2edit">click2edit</div>
</div>
</form>
<p>
<!--<div id="summernote-result"></div>-->
</p>
</div>
Javascript : Javascript:
$(document).ready(function() {
$('#summernote').summernote();
});
var edit = function() {
$('.click2edit').summernote({focus: true});
};
var save = function() {
var markup = $('.click2edit').summernote('code');
$('.click2edit').summernote('destroy');
};
You haven't explained what "doesn't work", but I'm guessing your form is submitting and you don't want it to. 您尚未解释什么“无效”,但我想您的表单正在提交,而您不希望这样做。 Remove the onclick inline JS and have the event callback prevent form submission:
删除onclick内联JS,并让事件回调阻止表单提交:
$('#save').on('click', function(e) {
e.stopPropagation();
var markup = $('.click2edit').summernote('code');
$('.click2edit').summernote('destroy');
return false;
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.