如何使用_this_ Jeditable来获得受控dom元素的值? [英] how to get to the value of manipulated dom element using _this_ Jeditable?

查看:84
本文介绍了如何使用_this_ Jeditable来获得受控dom元素的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是 可如何根据dom元素属性设置参数

请在这里回复.这是我的真实"帐户.

Please respond here.. this is my 'real' account..

我正在尝试为启用了jQuery插件"Jeditable"的不同div分配不同的参数值.我无法使其正常工作,我确定它很简单..但我无法弄清楚..

I'm trying to assign different parameter values to different divs on which I have enabled the jQuery plugin 'Jeditable'. I can't get it to work, I'm sure its something simple.. but I can't figure it out..

如何实现?

给出以下DOM元素:

<div class="editme" id="theone" rel="test"></div>

这些不同的代码片段为上述空div产生了以下dafault占位符文本:

These various snippets produce the following dafault placeholder texts for the above empty div:

$('.editme').editable('savedata.php',{
    placeholder : "txt -  "+$(this),
    }   
);
// outputs: "txt -  [object Object]"

$('.editme').editable('savedata.php',{
placeholder : "txt -  "+this,
}   
);
// outputs: "txt - [object HTMLDocument]"

$('.editme').editable('savedata.php',{
placeholder : "txt -  "+$(this).html(),
}   
);
// outputs: "txt - undefined"

$('.editme').editable('savedata.php',{
placeholder : "txt -  "+$(this).attr('rel'),
}   
);
// outputs: "txt - undefined"

$('.editme').editable('savedata.php',{
placeholder : "txt -  "+this.attr('rel'),
}   
);
// outputs: "" (NULL / EMPTY STRING, must be due to error)

推荐答案

不幸的是,当您在代码中使用this时,它引用的是参数集合,而不是您尝试访问的jQuery对象.要完成您要执行的操作,您将需要在参数集合之外引用jQuery对象.

Unfortunately, when you use this in your code it's referencing the parameter collection and not the jQuery object you are trying to access. To accomplish what you're trying to do, you will need reference the jQuery object outside of the parameter collection.

类似的东西:

$('.editme').each( function() {
    var rel = $(this).attr('rel');
    $(this).editable('savedata.php', {
        placeholder : "zzz" + rel,
        }       
    );
});

这篇关于如何使用_this_ Jeditable来获得受控dom元素的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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