Tag: javascript

Backbone.js和jQueryMobile路由没有黑客或其他路由器

我正在使用backbone.js(0.5.3)和JQueryMobile(1.0 beta 2)。 我知道在一起使用这些库时存在路由冲突,我想知道是否有使用它们的解决方案: 没有像Ben Nolan的花盆那样侵入jquery移动源代码: http : //bennolan.com/2010/11/23/backbone-and-jquery-mobile.html 并且不使用像jquerymobile-router这样的其他路由器(除非没有其他选项…) 我的问题与本文中描述的问题非常相似: jquery-mobile backbone.js routing 当我发出请求时,在新的jquery页面完全加载之前,会触发相应骨干视图的主干render代码。 我正在尝试在$(“.ui-page-active”) DOM元素中呈现我生成的html代码,以定位由jQueryMobile(或“激活”的页面)生成的页面: MyView = Backbone.View.extend({ el: $(“.ui-page-active”) render: function(){ console.log(el) } }); 但是调用render方法时el属性为空,因为jquery mobile还没有渲染dom … 谢谢你的帮助 ! 更新 Addy Osmani似乎有我的问题的答案:)但它将是他的(伟大的)教程的下一部分: http : //msdn.microsoft.com/en-us/scriptjunkie/hh377172.aspx

html5canvas中的碰撞检测

我正在尝试构建一个游戏,用户应该将圆圈放在垂直条中,但我在碰撞检测function方面遇到了麻烦。 这是我的jsfiddle: http : //jsfiddle.net/seekpunk/QnBhK/1/ if (collides(Bluecircle, longStand)) { Bluecircle.y = longStand.y2; Bluecircle.x = longStand.x2; } else if (collides(Bluecircle, ShortStand)) { Bluecircle.y = ShortStand.y2; Bluecircle.x = ShortStand.x2; } function collides(a, bar) { return ax == bar.x1 && ay == bar.y1; }

修复IE中的背景位置

当我运行一段使用jquery和2个jquery插件的代码时,我在IE7中遇到了这个问题。 该代码适用于FF3和Chrome。 完整的错误是: Line: 33 Char: 6 Error: bg is null or not an object Code: 0 URL: http://localhost/index2.html 然而,第33行是空白行。 我正在使用2个插件:draggable和zoom。 无论我对代码做什么,总是第33行出错。 我通过查看源检查源是否有更新,但我觉得这可能对我说谎。 $(document).ready(function() { $(‘#draggable’).drag(); $(‘#zoom’).zoom({target_div:”draggable”, zoom_images:new Array(‘https://stackoverflow.com/questions/594870/fix-for-background-position-in-ie/tiles/mapSpain-smaller.jpg’, ’tiles/mapSpain.jpg’) }); }); 基本上我要做的是用jQuery重新创建Pragmatic Ajax地图演示。 看来这段代码的第二行造成了麻烦: bg = $(this).css(‘background-position’); if(bg.indexOf(‘%’)>1){ 它似乎试图选择#draggable的背景位置属性而不是找到它? 手动添加background-position: 0 0; 没有解决它。 关于如何解决这个问题的任何想法? 我尝试使用MS脚本调试器,但这几乎没用。 无法检查变量或其他任何内容。

如何检查用户是否有网络摄像头?

我需要知道是否有办法知道用户是否在他的计算机上使用javascript或php进行了网络摄像头。

使用javascript / jquery动态调整canvas窗口的大小?

如何使用javascript / jquery调整canvas大小? 使用css函数resize并将其应用于canvas元素只会拉伸内容,就像拉伸图像一样。 如果没有伸展,我该怎么做呢? http://jsfiddle.net/re8KU/4/

我可以强制jQuery Deferred / Ajax在解决后执行失败处理程序吗?

一个例子,以明确我想做什么。 这就是我通常会做的事情: function success(data, status, jqxhr){ if ( data.error ) return failure(jqxhr, status, data.error); // process data } function failure(jqxhr, status, err){ … } $.ajax( … ) .done(success) .fail(failure) 有什么办法,我可以用匿名函数来完成这个,就像这样吗? $.ajax( … ) .done(function(data, status, jqxhr){ if(data.error) // what do i need to do here to jump in to the fail handler? }) .fail(function(jqxhr, status, […]

防止在父级而非子级上触摸移动默认值

我正在为iPad创建一个小的Web应用程序,我有几个元素,我阻止用户通过阻止touchmove事件的默认滚动。 但是,我有一种情况,我需要用户能够滚动子元素。 我试过用e.stopPropagation(); 但没有运气! 我还尝试检测手指下的元素并放入e.preventDefault(); 在if语句中,但再次,没有运气。 或者也许我只是混淆了…… 有任何想法吗? 从#fix div中删除.scroll div是最后的手段,因为它会引起各种令人头疼的问题。 编辑 我设法对它进行排序。 好像我不明白使用.stopPropagation(); 哎呀! 工作代码: Hi there List item List item List item List item List item List item 和Javascript: $(‘body’).delegate(‘#fix’,’touchmove’,function(e){ e.preventDefault(); }).delegate(‘.scroll’,’touchmove’,function(e){ e.stopPropagation(); });

向jqGrid jQuery插件添加一个函数

我试图将一个名为rows的函数添加到jqGrid jQuery插件中,但我无法确定语法。 这是我的非工作版本。 (function($) { $.fn.jgrid.rows = function(data) { // do something }; }); (function($) { $.fn.rows = function(data) { // do something }; }); $.jqgrid.fn.rows = function(data) { // do something }; $.fn.rows = function(data) { // do something }; 什么是正确的语法? 谢谢!

如何将js变量发送到mvc控制器

我是客户端 – 服务器编程概念的新手。 我需要的是,向我的MVC 3控制器动作发送四个js变量。 $(document).ready(function() { var $jcrop; $(‘#image’).Jcrop({ bgColor: ‘red’, onSelect: refreshData }, function () { $jcrop = this; }); function refreshData(selected) { myData = { x1: selected.x1, x2: selected.x2, y1: selected.y1, y2: selected.y2 }; } }); 所以我在浏览器中获取我的变量。 我在服务器端有的是: public ActionResult CreateCover(ImageCoordinates coordinates) { ViewData.Model = coordinates; return View(); } public class ImageCoordinates […]

如何在sharepoint 2013中获取oauth访问令牌?

我在这里有这个网站: http : //msdn.microsoft.com/en-us/library/jj164022(v = office.15).aspx 某些部分的文本说:以下JavaScript代码演示了如何使用JQuery生成此GET请求,该请求返回所有站点列表的JSON表示。 它还假定您具有存储在accessToken变量中的有效OAuth访问令牌。 如果您从应用程序Web中进行此调用,则不需要访问令牌,就像在SharePoint托管的应用程序中一样。 jQuery.ajax({ url: http:// site url/_api/web/lists, type: “GET”, headers: { “ACCEPT”,”application/json;odata=verbose”, “Authorization”, “Bearer ” + accessToken }, }) 具体问题是如何获取访问令牌?