2个java脚本冲突
2 javascripts are conflicting
我有两个相互冲突的java脚本,新的(Zeroclipboard)与旧的(删除行)冲突,并且不会让删除行一个工作。我删除零剪贴板的那一刻,删除就成功了。
尝试添加jQuery.noConflict();但似乎不起作用。通过阅读一些解决方案,我决定删除$符号,但仍然没有。
我有一个files.php文件,包括header.php文件。我正在header.php中添加custom.js文件,该文件包含许多用于整个项目操作的函数,包括delete行函数。然而,ZerClipboard的新脚本在files.php中。
旧的一个,点击删除图标删除一个表行,在我添加下一个后就不起作用了:
custom.js
function deleteRow()
{
var current = window.event.srcElement;
while ( (current = current.parentElement) && current.tagName !="TR");
current.parentElement.removeChild(current);
}
$(document).ready(function()
{
$('table#delTable td a.delete').click(function()
{
if (confirm("Are you sure you want to delete?"))
{
var fid = $(this).parent().parent().attr('fid');
var str=$(this).attr('rel');
var data = 'fid=' + $(this).attr('rel') + '&uid=' + $(this).parent().attr('rel');
var deletethis = '#tr' + $(this).attr('rel');
var parent = $(this).parent().parent();
$.ajax(
{
type: "POST",
url: "delete.php",
data: data,
cache: false,
success: function(msg)
{
$(deletethis).fadeOut('slow', function() {$(this).remove();});
}
});
}
});
$('table#delTable tr:odd').css('background',' #FFFFFF');
});
ZeroClipboard的JS和SWF,连同此JS在剪贴板上复制一些文本的共享图标点击:
files.php
<script type="text/javascript" src="js/ZeroClipboard.js"></script>
<script language="JavaScript">
var clip = null;
function $(id) { return document.getElementById(id); }
function init()
{
clip = new ZeroClipboard.Client();
clip.setHandCursor( true );
}
function move_swf(ee)
{
copything = document.getElementById(ee.id+"_text").value;
clip.setText(copything);
if (clip.div)
{
clip.receiveEvent('mouseout', null);
clip.reposition(ee.id); }
else{ clip.glue(ee.id); }
clip.receiveEvent('mouseover', null);
}
</script>
我用这篇博客文章实现了多个zerclipboard-http://blog.aajit.com/easy-multiple-copy-to-clipboard-by-zeroclipboard/下面是files.php页面生成的HTML源代码-http://jpst.it/tlGU
删除第二个脚本的以下函数定义:
function $(id) { return document.getElementById(id); }
因为这是在window
上下文中重新定义$
对象,所以当您在第一个脚本中使用$
时,您不是在使用jquery
,而是在使用新的函数定义。
希望这有帮助,
以下是应该如何使用noConflict()
:
function deleteRow()
{
var current = window.event.srcElement;
while ( (current = current.parentElement) && current.tagName !="TR");
current.parentElement.removeChild(current);
}
jQuery.noConflict(); // Reinitiating $ to its previous state
jQuery(document).ready(function($) // "Protected" jQuery code : $ is referencing jQuery inside this function, but not necessarily outside
{
$('table#delTable td a.delete').click(function()
{
if (confirm("Are you sure you want to delete?"))
{
var fid = $(this).parent().parent().attr('fid');
var str=$(this).attr('rel');
var data = 'fid=' + $(this).attr('rel') + '&uid=' + $(this).parent().attr('rel');
var deletethis = '#tr' + $(this).attr('rel');
var parent = $(this).parent().parent();
$.ajax(
{
type: "POST",
url: "delete.php",
data: data,
cache: false,
success: function(msg)
{
$(deletethis).fadeOut('slow', function() {$(this).remove();});
}
});
}
});
$('table#delTable tr:odd').css('background',' #FFFFFF');
});
在files.php中:
<script src="js/ZeroClipboard.js"></script>
<script>
var clip = null;
function $(id) {
return document.getElementById(id);
}
function init() {
clip = new ZeroClipboard.Client();
clip.setHandCursor(true);
}
function move_swf(ee) {
copything = document.getElementById(ee.id + "_text").value;
clip.setText(copything);
if (clip.div) {
clip.receiveEvent('mouseout', null);
clip.reposition(ee.id);
} else {
clip.glue(ee.id);
}
clip.receiveEvent('mouseover', null);
}
</script>
- 为什么'滚动到顶部'脚本导致类型错误?jQuery冲突
- jQuery插件冲突和脚本声明顺序
- 同一页面上的多个Jquery脚本冲突
- jQuery与核心Joomla脚本冲突
- "$"未定义;jquery在<头部>;没有冲突的脚本或库
- 意外的脚本/css冲突,如何解决
- 冲突的脚本#选择器标记
- 脚本代码冲突
- PHP密码脚本和JavaScript刷新冲突,发出我想消除的表单重新提交消息
- 冲突的jQuery脚本(NoConflict修复了一个,但破坏了另一个)
- jquery与JS脚本冲突
- 为什么这 3 个 greasemonkey (javascript) 脚本相互冲突
- j查询冲突问题 - 停止运行脚本
- Google AMP 脚本与 jquery window.scroll 冲突
- Javascript 冲突 ajax 邮件和脚本
- RequireJS :处理与填充程序和非AMD加载脚本的jQuery冲突
- 冲突的脚本不起作用
- HTaccess与Ajax脚本冲突
- 冲突的 jQuery 对话框脚本
- 脚本冲突Mootools验证与jQuery幻灯片