- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一个在 chrome、FF2/3 和 IE9 中完美运行的 javascript
158: drop_area = $('#drop_area');
159: element = ui.helper;
但是我在 IE7 和 IE8 中得到以下错误:
SCRIPT438: Object doesn't support this property or method
dragdrop.js, line 158 character 2
我对 IE7 调试功能的了解非常有限,但看起来我无法真正从控制台检查有问题的对象。有谁知道这里可能发生了什么或者我如何才能更好地调试这个错误
编辑:意识到多一点上下文可能会有帮助
function on_element_drop(event, ui){
drop_area = $('#drop_area');
element = ui.helper;
on_element_drop 是 jQuery UI droppable 'drop' 事件的回调方法
/*
* dragdrop.js
* Author: Casey Flynn
* June 10, 2011
* Global variables available to all functions
*/
//Keeps track of elements present in droppable and corresponding offsets/positions
var base_url = 'http://www.bla/';
var global_positions = new Array();
var current_item_group = 0;
var loaded = new Array();
var preloading = true;
var items = new Array(
new Array(
new Array(0, '2-Dollar'),
new Array(1, 'Cards'),
new Array(2, 'Cheese'),
new Array(3, 'Coupons'),
new Array(4, 'DogTags')),
new Array(
new Array(5, 'Doodle'),
new Array(6, 'Dreamcatcher'),
new Array(7, 'Fish'),
new Array(8, 'Fortune'),
new Array(9, 'Groucho')),
new Array(
new Array(10, 'HandTurkey'),
new Array(11, 'Key'),
new Array(12, 'Lolipop'),
new Array(13, 'LotteryTicket'),
new Array(14, 'Map')),
new Array(
new Array(15, 'Napkin'),
new Array(16, 'Notepad'),
new Array(17, 'OldPhoto'),
new Array(18, 'Oragami'),
new Array(19, 'Photo_Baby')),
new Array(
new Array(20, 'Photo_DJ'),
new Array(21, 'Photo_Dogs'),
new Array(22, 'Photo_Moustache'),
new Array(23, 'Pick'),
new Array(24, 'RabitsFoot')),
new Array(
new Array(25, 'Recipe'),
new Array(26, 'Reminder'),
new Array(27, 'Ribbon'),
new Array(28, 'SheetMusic'),
new Array(29, 'Smiley')),
new Array(
new Array(30, 'Spork'),
new Array(31, 'Tape'),
new Array(32, 'Ticket'),
new Array(33, 'USB'),
new Array(34, 'Viewmaster')
)
);
/*
* jQuery 'ready' handler, executes after DOM is ready and
* sets draggable/droppable properties of associated elements
*/
$(function(){
for(var i = 0; i < items.length; i++)
loaded[i] = false;
load_elements(0);
$('#drop_area').droppable({
//accept: '.draggable',
//hoverClass: 'vel_content_active',
drop: on_element_drop
});
$('#countdown').html((10 - global_positions.length)+'');
});
// preloads an array of images
function preload(arrayOfImages) {
$(arrayOfImages).each(function(){
console.log('Preloading ' + this);
$('<img/>')[0].src = this;
// Alternatively you could use:
// (new Image()).src = this;
});
}
/*
* Loads the first set of elements from 'items'
*/
function load_elements(arg0){
set = items[arg0];
box_handle = $('.bottom_content');
elements = '';
//construct html for elements to be added
for(i=0; i<set.length; i++){
elements += '<div class="draggable"><img alt="' + set[i][0] + '" src="' + base_url + 'application/assets/images/items/' + set[i][1] + '.png" /></div>';
}
//clear whatever was in there
box_handle.empty();
// element parent container
box_handle.html(elements);
//assign draggable status
$('.draggable').draggable({
revert: true,
revertDuration: 0,
helper: 'clone'
});
loaded[arg0] = true;
if(preloading){
var prev = next_elements(-1);
var next = next_elements(1);
if(!loaded[prev]){
preload(items[prev])
loaded[prev] = true;
}
if(!loaded[next]){
preload(items[next])
loaded[prev] = true;
}
}
}
function next_elements(arg0){
if((current_item_group + arg0) == -1){
return 6;
}else{
return ((current_item_group + arg0) % 7);
}
}
/*
* Cycles through element groups presented in .bottom_content
-1 to the left 1 to the right
*/
function cycle_elements(arg0){
if((current_item_group + arg0) == -1){
current_item_group = 6;
}else{
current_item_group = ((current_item_group + arg0) % 7);
}
load_elements(current_item_group);
}
/*
* Callback function on drop event for droppable
* Determines position of dropped element in droppable
*/
function on_element_drop(event, ui){
drop_area = $('#drop_area');
element = ui.helper;
//Find relative x/y position of element inside drop_area
var x = Math.floor((element.offset().left - drop_area.offset().left) / drop_area.width() * 100);
var y = Math.floor((element.offset().top - drop_area.offset().top) / drop_area.height() * 100);
//console.log(ui); return;
//console.log(ui.draggable.context.className.indexOf('draggable_dropped'));
if(ui.draggable.context.className.indexOf('draggable_dropped') == -1){
if(global_positions.length >= 10)
return;
//record element position and id
row = new Array(parseInt($(ui.draggable).find("img").attr('alt')),
x,
y);
//Add copy of item to drop_area at same x/y position where it was dropped
add_element_copy_to_div(row);
add_element_copy_to_global_positions(row);
}else{
//Item has already been dropped and is being adjusted, update global_positions
//update global_positions
id = ui.draggable.context.id;
update_global_positions(id, x, y);
}
//$('#countdown').html((10 - global_positions.length)+'');
console.log(global_positions);
}
/*
* Finds element in global_positions and updates x & y values
*/
function update_global_positions(id, newX, newY){
image_id = global_positions[id][0];
global_positions[id] = new Array(image_id, newX, newY);
/*
var old_array = global_positions[find_index(global_positions, index)];
var new_array = new Array(old_array[0], newX, newY);
//.splice(i,1,pos) -- remove 1 element at index i and replace with pos
global_positions.splice(index,1,new_array);
*/
}
/*
* Helper function, determines if element is already present in 'global_positions'
* Replaces if present, adds otherwise
*/
function add_element_copy_to_global_positions(pos){
global_positions.push(pos);
/*
var found = false;
for(i=0;i<global_positions.length;i++){
if(global_positions[i][0] == pos[0]){
//.splice(i,1,pos) -- remove 1 element at index i and replace with pos
global_positions.splice(i,1,pos);
found = true;
}
}
if(!found)
global_positions.push(pos);
*/
}
/*
* Helper function, adds a copy of the draggable that was dropped into the droppable
* for user visualization
*/
function add_element_copy_to_div(pos){
drop_area = $('#drop_area');
id = global_positions.length;
console.log('id: ' + id);
//Convert % x&y offsets into absolute pixel offsets based on div size
x = Math.floor(drop_area.width() * (pos[1] / 100));
y = Math.floor(drop_area.height() * (pos[2] / 100));
/*------- Find filename of image that has been dropped ------*/
index = find_index(items[current_item_group], pos[0]);
filename = items[current_item_group][index][1];
drop_area.append('<div style="position:absolute;" class="draggable_dropped" id="' + id + '"><img src="' + base_url + 'application/assets/images/items/' + filename + '.png" /></div>');
$('#'+id).css('left', x);
$('#'+id).css('top', y);
//Set the newly dropped element to draggable so it can be repositioned
$('#'+id).draggable({
stop:function(event, ui){
if(!is_valid_position(ui)) //invalid drop
delete_item(ui);
}
});
}
/*
* deletes element from global_positions and #drop_area when user drops item outside #drop_area
* also adjusts id attributes of all items
*/
function delete_item(ui){
id = ui.helper.context.id;
$('#'+id).remove();
global_positions.splice(id, 1);
$('#drop_area div').each(function(index){
if(parseInt($(this).attr('id')) > parseInt(id))
$(this).attr('id', parseInt($(this).attr('id')) - 1);
});
console.log(global_positions);
}
/*
* helper for add_element_copy_to_div
*/
function is_valid_position(ui){
drop_area = $('#drop_area');
element = ui.helper;
//Find relative x/y position of element inside drop_area
var x = Math.floor((element.offset().left - drop_area.offset().left) / drop_area.width() * 100);
var y = Math.floor((element.offset().top - drop_area.offset().top) / drop_area.height() * 100);
if( (x < -5) ||
(x > 105) ||
(y < -5) ||
(y > 105))
return false;
return true;
}
/*
* helper for add_element_copy_to_div
*/
function find_index(items, search_index){
for(i=0; i < items.length; i++){
if(items[i][0] == search_index)
return i;
}
}
/*
* Convert global_position array to JSON and submit to server via ajax along with csrf_token
*/
function update_layout(){
$.ajax({
url: '/projects/velcro/index.php/welcome/update_layout',
type: 'post',
data: {'layout_json' : $.toJSON(global_positions), 'ci_csrf_token' : $('input[name=ci_csrf_token]').val()},
success: function(data, textStatus, jqXHR){
//Redirect user to next page here...
if(data == '1'){
//alert('Layout successfully saved');
}else{
//alert('Layout save failed');
}
location.href = 'http://www.messageamplify.com/projects/velcro/index.php/welcome/create2';
},
error: function(jqXHR, textStatus, errorThrown){
console.log('error: '+jqXHR);
console.log(textStatus);
console.log(errorThrown);
}
});
}
//End file 'dragdrop.js'
最佳答案
drop_area = $('#drop_area');
此行将总是在 IE 中抛出错误。这是因为在 IE 中,每个具有 id 的元素都可以通过全局 window
对象访问,在本例中为 window.drop_area
。但是 window
是一个全局对象的事实使得可以在没有全局对象的情况下访问该对象,在这种情况下,只需 drop_area
。
因此,drop_area = $('#drop_area');
这句话并不是试图将对象分配给变量,而是试图覆盖元素 引用与另一个对象。这是您看到的运行时异常错误。
要绕过此异常,您需要将 jQuery 对象分配给一个变量。为此,您有两种选择:
var
语句在包含代码的函数内限定变量的范围,并从全局隐藏对 window.drop_area 的访问,例如 var drop_area = $('#drop_area' );
, 或 var dropArea = $('#drop_area');
并且,作为一个好建议,请始终使用 var
语句为您使用的变量提供一个范围。
关于Javascript/jQuery : SCRIPT438 error with IE7/8, 有什么调试技巧吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6527697/
我知道 source 和 . 做同样的事情,如果标题中的其他命令对不一样,我会感到惊讶事情(因为我正在运行 bash 作为我的 shell,$SHELL [script] 和 bash [script
我在尝试启动第一个 super 账本网络时遇到此错误: $ ./byfn.sh -m up Starting with channel 'mychannel' and CLI timeout of '
哪个更好用或者更方便: ... 或 ... 最佳答案 你真的需要类型属性吗?如果您使用的是 HTML5,则不会。否则,是的。 HTML 4.01 和 XHTML 1.0 指定了 type属性是必需的,
哪个更好用或者更方便: ... 或 ... 最佳答案 你真的需要类型属性吗?如果您使用的是 HTML5,则不会。否则,是的。 HTML 4.01 和 XHTML 1.0 指定了 type属性是必需的,
使用此语法包含外部 javascript 文件的正确术语是什么: 是否包含script.js?执行了吗?是链接的吗?是叫吗?我刚刚运行了该文件吗? 最佳答案 我认为这里最常见的术语是加载外部 Jav
这个问题在这里已经有了答案: 关闭 11 年前。 Possible Duplicate: Why don't self-closing script tags work? 我刚刚发现 HTML 中的
没什么可说的了。我尝试寻找这意味着什么,但找不到。该脚本几个月来一直运行良好,并在 12 小时前停止,没有对其进行任何更改。手动运行显示此错误。 最佳答案 我遇到了同样的问题,我只需从脚本编辑器中单击
我是 Apps 脚本的新手,正在尝试了解使用另一个帐户在一个帐户中运行/触发脚本的基础知识。需要注意的是:我想在访问脚本的用户而不是拥有脚本的用户的情况下运行脚本——以便将运行时间分配给访问的用户。
我是 Apps 脚本的新手,正在尝试了解使用另一个帐户在一个帐户中运行/触发脚本的基础知识。需要注意的是:我想在访问脚本的用户而不是拥有脚本的用户的情况下运行脚本——以便将运行时间分配给访问的用户。
我最近遇到这个问题,我试图在我的 HTML 页面中导入多个 js 文件,如下 - 但我面临的问题是,它只加载第一个 js 文件,而其余的 js 文件没有加载。我还检查了浏览器中的网络部分,剩下的
Duplicate Why don’t self-closing script tags work? 我正在编写一个 ASP.net 页面,它在 JS 文件中有一些用于客户端身份验证的 Javascr
为什么以下行在许多浏览器(mozilla、IE)中不起作用? 为什么一定要这样设置? 最近我将我的项目从 XHTML 转换为 HTML5,我遇到了一些小但令人不安的不兼容性。 最佳答案 虽然脚本元
这个问题已经有答案了: Why don't self-closing script elements work? (12 个回答) 已关闭 7 年前。 经过两天的 Angular 与 Webpack
我在任何地方都找不到这个问题的答案;甚至在官方文档中也没有。我已经尝试自己编写代码,但它不起作用,所以它可能无法实现。 在下面的示例中,您可以使用条件颜色进行绘图: //STACKED EMAs
我正在通过串行端口使用 Tera Term 在板上进行一些测试。最近我发现我可以在 Tera Term 中编写一些脚本,所以我一直在做研究以帮助自动化并使测试更容易一些。 我知道 Tera Term
数组在 PineScript 中不可用。 有解决办法吗?有没有人开发过代码,作为数组使用? 我需要它做什么?我想计算每条趋势线或 S/R 水平的触及次数。 最佳答案 要实现计数器,您可以创建一个变量,
有没有办法创建一个指标来反射(reflect) Pine Script 中股票的当前价格?我需要这个指标,因为我需要在蜡烛关闭之前输入订单(当有特定的交叉时)并且回测数据是逐条提供的。我认为一个指标可
我的网站有一个脚本,如果从移动设备查看页面,格式和样式会发生变化。在网站的 2/3 页上,该脚本效果很好,正如我想要的那样。但是在最后一个上,用于更改格式和样式的脚本运行但未完全运行。我已经尝试从我的
我是否正确,市场上没有直接替代此流程: 在 chrome 插件商店中发布未列出 直接将链接分享给可以使用脚本的人 特别是,这些机制允许我使用我在所有 google dsoc 上编写的脚本。 随着转向市
我有一个简单的 Google Script 发布为具有匿名访问权限的网络应用程序。代码可用 here网络应用程序可用 here . code.gs function doGet() { retur
我是一名优秀的程序员,十分优秀!