Вопрос

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.

http://jsfiddle.net/ncjbx/9/

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) {
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top