刘410521
2015-01-29 09:34
使用了这种方法,不需要引入javascript脚本了吧
没脚本谁来帮你执行这些.... 这个肯定是要的,区别在于这里面处理了
http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.js
自己去上面这个js文件里面找modal.js,里面有这一段js
$(document).on('click.bs.modal.data-api', '[data-toggle="modal"]', function (e) {
var $this = $(this)
var href = $this.attr('href')
var $target = $($this.attr('data-target') || (href && href.replace(/.*(?=#[^\s]+$)/, ''))) // strip for ie7
var option = $target.data('bs.modal') ? 'toggle' : $.extend({ remote: !/#/.test(href) && href }, $target.data(), $this.data())
if ($this.is('a')) e.preventDefault()
$target.one('show.bs.modal', function (showEvent) {
if (showEvent.isDefaultPrevented()) return // only register focus restorer if modal will actually get shown
$target.one('hidden.bs.modal', function () {
$this.is(':visible') && $this.trigger('focus')
})
})
Plugin.call($target, option, this)
})function Plugin(option, _relatedTarget) {
return this.each(function () {
var $this = $(this)
var data = $this.data('bs.modal')
var options = $.extend({}, Modal.DEFAULTS, $this.data(), typeof option == 'object' && option)
if (!data) $this.data('bs.modal', (data = new Modal(this, options)))
if (typeof option == 'string') data[option](_relatedTarget)
else if (options.show) data.show(_relatedTarget) <- 这儿就是将事件注册到target对象上
})
}
那为什么现在没有给出js脚本代码
...当然是需要的 这个给出的方法大概意思就是给定一个规范 bootstrap中的js脚本是根据data-toggle 和 data-target的值来完成交互的
玩转Bootstrap(基础)
314547 学习 · 2364 问题
相似问题