javascript - Bootstrap modal 3 check if button is clicked - Stack Overflow

I'm working on a project with fullcalendar and bootstrap v3 (newest)I want to use a modalbox boots

I'm working on a project with fullcalendar and bootstrap v3 (newest)

I want to use a modalbox bootstrap styled. I want to define my own buttons in the jQuery because that way I can keep all data inside the fullcalender functions.

Part of js

select:  function(start, end, allDay) { 
            $('#selectModal').on('#Create', function (e) {
              // do something...
            })
        },  

Bootstrap modal

<!-- Modal box for select -->
<div class="modal fade" id="selectModal" tabindex="-1" role="dialog" aria-labelledby="selectModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title">Modal title</h4>
      </div>
      <div class="modal-body">
        <form class="form-horizontal" role="form">
            <div class="form-group">
                <label>Medewerker</label>
                    <select class="form-control" id="selectBoxMedewerker">          
                        <?php foreach($this->users as $user):?>
                            <option  id="<?=$user->webuserId;?>" value="<?=$user->firstName;?> <?=$user->preposition;?> <?=$user->lastName;?>"><?=$user->firstName;?> <?=$user->preposition;?> <?=$user->lastName;?></option>
                        <?php endforeach;?>
                    </select>
            </div>
            <div class="form-group">
                <input type="text" id="description" class="form-control" placeholder="Description">
            </div>
        </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" id="Create" class="btn btn-primary">Create</button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

The Problem

If I strip out

$('#selectModal').on('#Create', function (e) {
              // do something...
            })

Everything works fine but when I add it (to check if create is clicked) I get this error in firebug:

SyntaxError: missing : after property id
$('#Create').click(function(){});

What am I doing wrong here ^

Updated Code:

select:  function(start, end, allDay) {
            $('#selectModal').modal({
                $('#selectModal').on('click','#Create', function (e) {alert('something')});
            });
        },  

Working Code

    $('#selectModal').modal({

    });
    $('#selectModal').on('click','#Create', function (e) {alert('something')});

There is still something wrong with the 'updated code'. I put the check on Create click out the modal and it works.

So my goal is reached. Thanks!

I'm working on a project with fullcalendar and bootstrap v3 (newest)

I want to use a modalbox bootstrap styled. I want to define my own buttons in the jQuery because that way I can keep all data inside the fullcalender functions.

Part of js

select:  function(start, end, allDay) { 
            $('#selectModal').on('#Create', function (e) {
              // do something...
            })
        },  

Bootstrap modal

<!-- Modal box for select -->
<div class="modal fade" id="selectModal" tabindex="-1" role="dialog" aria-labelledby="selectModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title">Modal title</h4>
      </div>
      <div class="modal-body">
        <form class="form-horizontal" role="form">
            <div class="form-group">
                <label>Medewerker</label>
                    <select class="form-control" id="selectBoxMedewerker">          
                        <?php foreach($this->users as $user):?>
                            <option  id="<?=$user->webuserId;?>" value="<?=$user->firstName;?> <?=$user->preposition;?> <?=$user->lastName;?>"><?=$user->firstName;?> <?=$user->preposition;?> <?=$user->lastName;?></option>
                        <?php endforeach;?>
                    </select>
            </div>
            <div class="form-group">
                <input type="text" id="description" class="form-control" placeholder="Description">
            </div>
        </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" id="Create" class="btn btn-primary">Create</button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

The Problem

If I strip out

$('#selectModal').on('#Create', function (e) {
              // do something...
            })

Everything works fine but when I add it (to check if create is clicked) I get this error in firebug:

SyntaxError: missing : after property id
$('#Create').click(function(){});

What am I doing wrong here ^

Updated Code:

select:  function(start, end, allDay) {
            $('#selectModal').modal({
                $('#selectModal').on('click','#Create', function (e) {alert('something')});
            });
        },  

Working Code

    $('#selectModal').modal({

    });
    $('#selectModal').on('click','#Create', function (e) {alert('something')});

There is still something wrong with the 'updated code'. I put the check on Create click out the modal and it works.

So my goal is reached. Thanks!

Share Improve this question edited Mar 25, 2014 at 12:37 JochemQuery asked Mar 25, 2014 at 12:25 JochemQueryJochemQuery 1,5672 gold badges27 silver badges39 bronze badges 1
  • need an event declaration in the .on() call (e.g. .on('click','#Create',function(){ ... })) – Brad Christie Commented Mar 25, 2014 at 12:27
Add a ment  | 

2 Answers 2

Reset to default 3

The correct syntax for on() is .on( events [, selector ] [, data ], handler(eventObject) ) where events is mandatory. Hence specify click event

$('#selectModal').on('click','#Create', function (e) {
});

Try replacing:

$('#Create').click(function(){});

With:

$('#Create').on('click',function(){

});

Your current statement is being interpreted as an object literal.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745179557a4615357.html

相关推荐

  • javascript - Bootstrap modal 3 check if button is clicked - Stack Overflow

    I'm working on a project with fullcalendar and bootstrap v3 (newest)I want to use a modalbox boots

    3小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信