admin管理员组文章数量:1435859
In the ments section on a blog I'm coding I want the admin to be able to delete a ment.
I have a button next to each ment and I want a modal box to be opened when the delete button
is clicked.
In this modal box I want to ask again if the ment should be deleted or not, if yes then it should lead me back to the post and the ment should be deleted.
Do I need javascript to do this? Unfortunately I'm new to php and I wondered if it's possible to only do it with html & css.
I have a PostsController.php
in which the site is rendered (action page) and I have the CommentsRepository.php
in which the connection to the db table ments
takes place.
This is the part of the ment section:
<div class="ments-list">
<?php foreach ($ments AS $ment): ?>
<div class="one-ment">
<p><?php echo e($ment->content); ?></p>
<div class="one-ment-edit">
<input type="button" value="x" name="delete" class="delete-ment" />
</div>
</div>
<?php endforeach; ?>
</div>
I know how to do the query, but I don't know how to open the modal box when the button is clicked.
I would really appreciate if someone can help me, especially if I need javascript to do this.
In the ments section on a blog I'm coding I want the admin to be able to delete a ment.
I have a button next to each ment and I want a modal box to be opened when the delete button
is clicked.
In this modal box I want to ask again if the ment should be deleted or not, if yes then it should lead me back to the post and the ment should be deleted.
Do I need javascript to do this? Unfortunately I'm new to php and I wondered if it's possible to only do it with html & css.
I have a PostsController.php
in which the site is rendered (action page) and I have the CommentsRepository.php
in which the connection to the db table ments
takes place.
This is the part of the ment section:
<div class="ments-list">
<?php foreach ($ments AS $ment): ?>
<div class="one-ment">
<p><?php echo e($ment->content); ?></p>
<div class="one-ment-edit">
<input type="button" value="x" name="delete" class="delete-ment" />
</div>
</div>
<?php endforeach; ?>
</div>
I know how to do the query, but I don't know how to open the modal box when the button is clicked.
I would really appreciate if someone can help me, especially if I need javascript to do this.
Share Improve this question asked Jan 10, 2019 at 10:03 ofmiceandmoonofmiceandmoon 6062 gold badges14 silver badges30 bronze badges3 Answers
Reset to default 2You don't need javascript, but it sure makes the thing easier!
I've found some examples of pop-up that are opened without any javascript. I find this one intersting:
- Pure CSS popup/modal box without javascript
To do so, they create a pop-up with a visibility: hidden;
css attribute, and they use the target pseudo-class to set this attribute to visibility: visible;
To trigger the target pseudo-class, they create a link (that acts like a button) that references the ID of your pop-up.
The link will target your pop-up, triggering the target pseudo-class, and showing your pop-up!
There is also the Bootstrap option, as remended by Jeppe Spanggaard, which works fine!
Hope it helped in any way!
You can use javascript for this: https://www.w3schools./howto/howto_css_modals.asp
But if you use Bootstrap there is an easier way: https://www.w3schools./bootstrap/tryit.asp?filename=trybs_modal&stacked=h
You can use SweetAlert for your cause, it is more elegant and easy to use.
https://sweetalert2.github.io/
here's working example: Jsfiddle
Simply on Delete Button click Apply following Code
Swal({
title: 'Are you sure?',
text: "You won't be able to revert this!",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!'
}).then((result) => {
if (result.value) {
Swal(
'Deleted!',
'Your file has been deleted.',
'success'
)
}
})
Here's how it will look,
EDIT
Based on your ment I think this might be helpfull JsFiddle
You can customize the popup like this Example
本文标签: javascriptHow to open modal when a button is clickedStack Overflow
版权声明:本文标题:javascript - How to open modal when a button is clicked - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745674895a2669792.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论