gpt4 book ai didi

javascript - JsFiddle:Library "Load Type"是指该库还是我的代码?

转载 作者:行者123 更新时间:2023-12-02 22:08:24 30 4
gpt4 key购买 nike

这看起来很明显,但我不太确定,并且 documentation is ambiguous .

我正在使用 jsFiddle (特别是这个, https://jsfiddle.net/suterma/dmqr5fe2/7/ 但问题更笼统)

$("textarea, input").bind("paste", function(e){
//...
});

我使用 jQuery,无论我将 jQuery 库的加载类型设置为“on Load”还是“bottom of head”,它都会在功能上产生差异。

现在,这个加载类型实际上是指如何加载 jQuery 库或如何加载我的代码片段吗?

我尝试使用开发人员模式来深入查看结果 Pane ,但是非常复杂,我还没有弄清楚。

最佳答案

您可以通过检查内部 iframe 或记录文档的 innerHTML 来检查它。 。例如,将其添加到您的代码中:

console.log(document.documentElement.innerHTML);

你会得到

<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title></title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="robots" content="noindex, nofollow">
<meta name="googlebot" content="noindex, nofollow">
<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- LOOK HERE: ----------------------------------------------------------------->
<script type="text/javascript" src="//code.jquery.com/jquery-2.1.3.js"></script>

<link rel="stylesheet" type="text/css" href="/css/result-light.css">


<style id="compiled-css" type="text/css">
textarea{
display:block;
width: 100%;
height: 200px;
}

input{
display:block;
width: 100%;
}
</style>


<!-- TODO: Missing CoffeeScript 2 -->

<script type="text/javascript">//<![CDATA[
// LOOK HERE: ---------------------------------------------------------------------
$(window).load(function(){

console.log(document.documentElement.innerHTML);
$("textarea, input").bind("paste", function(e){
e.stopPropagation();
e.preventDefault();

var cd = e.originalEvent.clipboardData;

var text = cd.getData("text/plain");

$(this).val(text.trim());
});

});

//]]></script>

</head>
<body>
<textarea id="pastezone" placeholder="Copy someting with leading and trailing spaces here, then it gets trimmed!"></textarea>

<input id="pastebox" placeholder="Copy someting with leading and trailing spaces here, then it gets trimmed!">



<script>
// tell the embed parent frame the height of the content
if (window.parent && window.parent.parent){
window.parent.parent.postMessage(["resultsFrame", {
height: document.body.getBoundingClientRect().height,
slug: ""
}], "*")
}

// always overwrite window.name, in case users try to set it manually
window.name = "result"
</script>


</body>

如您所见,库 (jQuery) 正在立即加载,位于 <script> 中。头上的标签。相反,您的代码放在 $(window).load(function(){ 内回调。

请注意,文档运行时运行代码的方法取决于所使用的库。例如,如果您取消选择 jQuery 并使用 D3.js(或任何其他库),您的代码将被放入 window.onload = function() { 中。回调。

关于javascript - JsFiddle:Library "Load Type"是指该库还是我的代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59641055/

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