Common syntax mistake. This:
if (modalshow = true) {
Should be this:
if (modalshow == true) {
As it is, you are setting modalshow
back to true
every time.
سؤال
I'm using a Bootstrap Modal and I want to have it show up only once when a button is clicked, but not if the button is clicked again.
I want to do this using a boolean that is initially true and when the button is clicked is set to false. I have actually found a solution just removing the Modal using .remove() after it is hidden the first time, but I want to know why a Boolean won't work.
var modalshow = true;
$("#button").click (function () {
if (modalshow = true) {
$("#myModal").modal("show");
modalshow = false;
}
})
المحلول
Common syntax mistake. This:
if (modalshow = true) {
Should be this:
if (modalshow == true) {
As it is, you are setting modalshow
back to true
every time.
نصائح أخرى
Change
if (modalshow = true) {
to
if (modalshow == true) {