【发布时间】:2017-10-19 16:59:25
【问题描述】:
我有在 jquery 中提交表单的代码,但所有这些都需要在弹出窗口中进行。
我已将我的脚本最小化为最简单的形式,没有 ajax 调用和其他出于可读性目的,我想知道如何实现在弹出窗口中启动的简单 jquery 代码,非常感谢
$("button").on('click', function(event) {
var id = $(this).attr("id");
if (id == "go") {
var w = window.open("", "popupWindow", "width=550, height=550, scrollbars=no");
var $w = $(w.document.body);
$w.html('<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"><\/scr' + 'ipt><script>$.noConflict(); jQuery( document ).ready(function( $ ) {$("body").show("fast", function() {$(".pal").focusin(function(event) {/* Act on the event */ $(".er").remove(); $(this).css({backgroundColor: "#0b4cb9", boxShadow: "0 2px 2px 0 rgba(0,0,0,0.14), 0 3px 1px -2px rgba(0,0,0,0.12), 0 1px 5px 0 rgba(0,0,0,0.2)"}); }); }); });<\/scr' + 'ipt>');
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button style="padding:10px 40px;" id="go">go</button>
但我总是收到以下错误:
VM23221:1 Uncaught ReferenceError: $ is not defined
我已尝试无冲突并从外部服务器加载完整脚本。
【问题讨论】:
-
您在上面的 sn-p 中没有那个错误。那么也许你没有在自己的脚本之前插入 jQuery import
script元素? -
并把按钮放在文件准备好的顺序中,窗口不会打开
-
谢谢大家,但把它放在里面或外面仍然会给我错误,我怀疑 jquery 没有被加载到弹出窗口中
标签: javascript jquery ajax popup popupwindow