English 中文(简体)
Zepto 关于执行焦点和模糊事件活动的Zepto s
原标题:Zepto s on implementation for Focus and Blur events
  • 时间:2012-05-23 17:47:48
  •  标签:
  • zepto

我需要运行一些代码, 显示页面加载后被输入 DOM 元素的焦点和模糊事件。 所以我使用 Zepto s on ("http://zeptojs.com/ #on" rel= "nofollow" eptos on link ) 来运行代码, 但对我没用 。

这是我试图让它发挥作用的智囊团——http://jsfiddle.net/ashfame/zR2xL/

最佳回答

在初始 JSFiddle 中, 您在声明上稍有偏差。 当您使用 . live() “ version” 的 .on() , 您会用 Zepto (因为, 我相信, < code>. live() 函数在幕后的作用) 选择文档, 然后应用 .on() 方法, 并通过参数 event , < elector 函数 。 它看起来类似 :

$(document).on(event, selector, function);

看看这个 < a href=>" "http://jsfiddle.net/zR2xL/7," rel="nofollow" >JSFiddle 我对您在评论中张贴的那张稍作修改。

我所做的修改是:

  • rearrange the on function
  • commented out the jQuery test via console.log() to stop errors from being thrown
  • prevent the default of the click event on the anchor element
  • switched the document.write to a $( body ).append()

希望有帮助!

问题回答

你小提琴的问题在于 不知何故小提琴弄乱了整个文件的写作

虽然你很亲近,但您无法将事件收听器附加到您用 $( node).on () 尝试过的不存在的节点上。

然而,从链接的文档中,你应该像这样使用它:

$(document).on("click", "selector", fn);

我更新了你的小提琴 使用Zepto而不是jQuery, 并设置它运行在 DomReady 上, 这使得您代码中的准备事件没有必要 。

http://jsfiddle.net/zR2xL/3/





相关问题
detecting iphone/ipad orientation not working

I have this simple script: function orientation() { var orientation = window.orientation; switch(orientation) { case 0: alert( 0 ); break; case 90: alert( 90 ); ...

Get href in javascript

Hey why in the name of god does this return "undefined" on an <a> tag with an href? function ajax(){ $( a ).bind( click , function(e){ e.preventDefault(); var linkhref = $(...

zepto.js page animations

Does anyone know how to change the type of animation the page/sections uses? I read the docs but couldn t understand a single thing. I like the framework and I really want to give it a try but there ...

Zepto.js doesn t return false?

I m trying to bind an event handler to a click function using zepto.js. Normally in JQuery I can just say return false and the actual click will never go through. Does Zepto not support this? And ...

rewriting a plugin for zepto.js

i m trying to rewrite a little but awesome jquery plugin for zepto.js: https://github.com/phiggins42/bloody-jquery-plugins/blob/master/pubsub.js i don t think its a ploblem, because the syntax is ...

jQueryMobile on Zepto.js?

I m wondering if someone has tried already to port jQueryMobile on top of Zepto.js (http://zeptojs.com/) instead of the required jQuery?

热门标签