문제

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