"ui"的jQuery UI对象类型;对象传递给回调函数? [英] jQuery UI object type for "ui" object passed to the callback function?

查看:88
本文介绍了"ui"的jQuery UI对象类型;对象传递给回调函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在jQuery UI中,传递给许多事件方法的回调函数的"ui"对象的类型/内容是什么,如何使用它?

In jQuery UI, what is the type/contents of the "ui" object passed to the callback function of alot of the event methods, and how do I use it?

例如,"可选"演示,事件"

For example, the "selectable" demo, the event "selected" gets passed two params. "Event" and "UI". I am trying to use it as follows:

    $("#selectable").selectable({ 
      selected: function(event, ui) { 
        $(ui).find("input").attr('checked', true); 
      } 
    });

(这是html:)

<ol id="selectable"> 
    <li class="ui-state-default"><input type="checkbox" value="1" /></li> 
    <li class="ui-state-default"><input type="checkbox" value="2" /></li> 
    <li class="ui-state-default"><input type="checkbox" value="3" /></li> 
    <li class="ui-state-default"><input type="checkbox" value="4" /></li> 
    <li class="ui-state-default"><input type="checkbox" value="5" /></li> 
    <li class="ui-state-default"><input type="checkbox" value="6" /></li> 
    <li class="ui-state-default"><input type="checkbox" value="7" /></li> 
    <li class="ui-state-default"><input type="checkbox" value="8" /></li> 
    <li class="ui-state-default"><input type="checkbox" value="9" /></li> 
    <li class="ui-state-default"><input type="checkbox" value="10" /></li> 
    <li class="ui-state-default"><input type="checkbox" value="11" /></li> 
    <li class="ui-state-default"><input type="checkbox" value="12" /></li> 
</ol> 

但是它不起作用.我究竟做错了什么?我假设ui参数已设置为表示所选择的"li"的对象,但是当我尝试使用它时,情况似乎并非如此……

But it isn't working. What am I doing wrong? I'm assuming that the ui param is set to an object representing the "li" that is selected, but when I try and use it it doesn't seem to be the case...

示例(推荐答案

根据我的理解,(这仅仅是从观察和我不可思议的力量中得出的:咳嗽,咳嗽::推论)ui是一个对象或集合用户界面中正在作用的元素的数量.为了访问它们,您需要选择要使用的对象,而不是整体选择对象.例如.在droppable中,它是ui.draggableui.droppable.在您的示例中,ui.selected是可行的.

From what I understand, (and this is just from making observations and my incredible powers ::cough, cough:: of inference) ui is a object or collection of the elements that are being acted upon within the user interface. In order to access them, you need to pick the one you want to be using, rather than selecting the object as a whole. Eg. in droppable, it's ui.draggable or ui.droppable. In your example, ui.selected is what would work.

$("#selectable").selectable({
    selected: function(event, ui) {
       $(ui.selected).find("input").attr('checked', true);
    }
});

希望能回答您的问题.

这篇关于"ui"的jQuery UI对象类型;对象传递给回调函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆