我做了一个函数 appendScript 将在按钮单击事件上调用我的函数代码是
function appendScript() {
var v_js;
var head = document.getElementsByTagName('head')[0];
v_js = document.createElement('script');
v_js.type = 'text/javascript';
v_js.src = "/resource/1372205606000/jquery_min_js";
head.appendChild(v_js);
interval = self.setInterval(function () {
if (jQuery) {
window.clearInterval(interval);
var body = document.getElementsByTagName('body')[0];
v_js = document.createElement('script');
v_js.type = "text/javascript";
v_js.src = "/resource/1372176744000/bootstrap_min_js";
}
body.appendChild(v_js);
var v_css = document.createElement('link');
v_css.rel = "stylesheets";
v_css.type = "text/css";
v_css.href = "/resource/1372206945000/bootstrap_min_css";
body.appendChild(v_css);
}, 300);
var interval1 = self.setInterval(function () {
if (typeof (jQuery.fn.modal) !== 'undefined') {
console.log('Hello!!');
window.clearInterval(interval1);
jQuery(document.getElementsByTagName('body')[0]).append('<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button><h3 id="myModalLabel">Modal header</h3></div><div class="modal-body"><p>One fine body…</p></div><div class="modal-footer"><button class="btn" data-dismiss="modal" aria-hidden="true">Close</button><button class="btn btn-primary">Save changes</button></div></div>');
var bootstrapModal = $.fn.modal.noConflict(); // return $.fn.button to previously assigned value
$.fn.bootstrapModal = bootstrapModal;
$('#myModal').bootstrapModal('show');
}
}, 300);
}
我面临的错误是
Uncaught TypeError: Cannot read property 'defaults' of undefined bootstrap_min_js:6
(anonymous function) bootstrap_min_js:6
x.extend.each jquery_min_js:4
x.fn.x.each jquery_min_js:4
e.fn.modal bootstrap_min_js:6
(anonymous function)