gpt4 book ai didi

javascript - 如何在通过单击超链接打开 Bootstrap 模式后将值设置为 Bootstrap 模式上的文本框?

转载 作者:行者123 更新时间:2023-11-29 19:17:42 25 4
gpt4 key购买 nike

我在我的网站中使用 Bootstrap v3.3.5

我有一个超链接,点击它会打开一个 Bootstrap 模式对话框。该超链接的 HTML 如下:

<a href="#myModal-add-event" data-toggle="modal">Add Event</a>

模态对话框的HTML代码如下:

<div id="myModal-add-event" class="modal fade" role="dialog">
<div role="document" class="modal-dialog add-event">
<div class="modal-content">
<div class="modal-body">
<h4 class="modal-title event-title">Add an Event</h4>
<form method="post" action="{$site_url}add_event.php" id="formAddEvent" >
<!-- The gmail look alike loader should display here only upon successfull submission of a form. -->
<div class="form-group" id="addEventErrorMsg" style="display:none; color:#FF0000;">
</div>
<div class="form-group">
<input type="text" name="txt_event_title" id="txt_event_title" autocomplete="off" class="form-control custom-height" placeholder="Event Title" style="height:30px;" />
</div>
<div class="form-group">
<textarea type="text" name="txt_event_description" id="txt_event_description" autocomplete="off" class="form-control custom-height" placeholder="Description (optional)" style="height:60px;" ></textarea>
</div>
<table border="0" cellspacing="10">
<tr>
<th><span class="event-title1" style="margin-bottom:5px;">Start Date:</span></th>
<th><span class="event-title1" style="margin-bottom:5px;">End Date:</span></th>
</tr>
<tr>
<td>
<div style="margin-right:15px;" class="form-inline form-group event-selection">
<div class="form-group has-feedback">
<div class='input-append date form_datetime' data-date="2013-02-21T15:25:00Z">
<input type='text' id='event_start_date' name="event_start_date" style="width:225px; display:inline; height:30px;" class="form-control" autocomplete="off" />
<span aria-hidden="true" class="glyphicon glyphicon-calendar form-control-feedback"></span>
</div>
</div>
</div>
</td>
<td>
<div class="form-inline form-group event-selection">
<div class="form-group has-feedback">
<div class='input-append date form_datetime' data-date="2013-02-21T15:25:00Z">
<input type='text' id='event_end_date' name="event_end_date" style="width:225px; display:inline;height:30px;" class="form-control" autocomplete="off" />
<span aria-hidden="true" class="glyphicon glyphicon-calendar form-control-feedback"></span>
</div>
</div>
</div>
</td>
</tr>
</table>
<div class="form-group has-feedback">
<input type="text" name="txt_event_location" id="txt_event_location" autocomplete="off" class="controls form-control custom-height" placeholder="Event Location" style="height:30px;" />
<span class="glyphicon glyphicon-map-marker form-control-feedback" aria-hidden="true"></span>
</div>
<div style="clear:both;"> </div>
<div id="map"></div>
<div class="form-group">
<input type="text" name="txt_event_room" id="txt_event_room" autocomplete="off" class="form-control custom-height" placeholder="Room No." style="height:30px;" />
</div>
<div class="form-group">
<div id="custom-templates">
<input class="typeahead form-control custom-height" id="selected_groupname" name="selected_groupname" type="text" placeholder="Invite Group">
<input type="hidden" name="selected_groupid" id="selected_groupid" value="" />
</div>
</div>
<div class="modal-footer text-center">
<button class="btn btn-primary" id="btn_add_event" type="button">Add Event</button>
<button data-dismiss="modal" class="btn btn-default" type="button">Cancel</button>
</div>
</form>
</div>
</div>
</div>
</div>

我想将值设置为 Hello...How are you? 到 ID 为 'selected_groupname'

的文本框中

为此,我尝试了以下代码,但它对我不起作用。

$(document).ready(function() {
$(function() {
$('#myModal-add-event').bind('show',function(){
$("#selected_groupname").val('Hello...How are you?');
});
});
});

此外,我还检查了 Firebug 控制台。我也没有收到任何错误或警告。

请有人帮助我。

最佳答案

我认为您没有将函数绑定(bind)到模态的正确事件。

Bootstrap modals 有一些自定义事件用于连接到模态功能:show.bs.modal, shown.bs.modal, hide.bs.modal, hidden.bs.modal, loaded.bs.modal.

您应该使用的事件是 show.bs.modal,它会在调用 show 实例方法时立即触发。

试试下面的代码:

$(document).ready(function() {
$('#myModal-add-event').on('show.bs.modal',function(){
$("#selected_groupname").val('Hello...How are you?');
});
});

您可以在此处阅读有关 Bootstrap 模式事件的更多信息:http://getbootstrap.com/javascript/#modals-events .

关于javascript - 如何在通过单击超链接打开 Bootstrap 模式后将值设置为 Bootstrap 模式上的文本框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34542670/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com