gpt4 book ai didi

javascript - colpick 不适用于 .html 到 .php 扩展名更改

转载 作者:行者123 更新时间:2023-12-03 10:19:44 24 4
gpt4 key购买 nike

我正在使用这个 Color Picker Jquery 插件 ( http://colpick.com/plugin )

问题是,我在 .html 中尝试了相同的简单代码,但是当我仅将扩展名更改为 .php 时,颜色选择器不起作用,而其他一切都有效。

一个简单的按钮,并添加了重要的脚本,如 colpick.js 和 colpick.css。

示例:

index.html

<html>
<head>
<script src="jquery-2.1.3.min.js"></script>
<script src="canvasSettings.js"></script>
<script src="colpick.js" type="text/javascript"></script>
<link rel="stylesheet" href="colpick.css" type="text/css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
</head>
<body>
<button id="idColor">Show Color Picker</button>
</body>
</html>

canvasSettings.js

$(document).ready(function()
{

alert("First");

$('#idColor').colpick();

alert("Second");

});

因此,在index.html中,当您单击按钮时,它会打开颜色选择器,并且两个警报都会显示,这里一切都很好。

问题是,当我将index.html更改为index.php(使用PHP服务器时)时,网站正常加载,按钮显示,并且出现“First”警报。
但是,当它到达 $("#idColor").colpick({}) 时,它不会处理,“第二个”警报不会显示。请记住 $("idColor").val() 有效。

即使 html 代码相同,是否有任何特殊方法可以将此 .html 更改为 .php?

最佳答案

您误判了问题。它与从 PHP 提供 HTML 而不是静态文件无关。

在这里加载 jQuery:

<script src="jquery-2.1.3.min.js"></script>

然后加载将自身绑定(bind)到 jQuery 的插件:

<script src="colpick.js" type="text/javascript"></script>

然后您再次加载 jQuery(但版本不同):

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>

覆盖之前的 jQuery 对象和您绑定(bind)到它的颜色选择器插件。

<小时/>
  1. 决定您要使用哪个版本的 jQuery(速度更快的 2.x 或 1.x,支持旧版本的 IE)。
  2. 在加载插件之前加载它(您目前在 2.x 中执行此操作,但在 1.x 中则不然)
  3. 不要加载其他版本

关于javascript - colpick 不适用于 .html 到 .php 扩展名更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29698774/

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