如何获得可选jQuery元素的innerHTML? [英] How to get the innerHTML of selectable jquery element?

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

问题描述

我有一个php生成的列表,其列表项可以使用jquery可选小部件进行选择。所有意图和目的列表如下:

I have a php generated list whose list items are selectable using jquery selectable widget. The list for all intents and purposes is:

<ul id="#select-image">
    <li class="ui-widget-content">Item 1</li>
    <li class="ui-widget-content">Item 2</li>
    <li class="ui-widget-content">Item 3</li>
    <li class="ui-widget-content">Item 4</li>
    <li class="ui-widget-content">Item 5</li>
    <li class="ui-widget-content">Item 6</li>
    <li class="ui-widget-content">Item 7</li>
</ul>

jQuery selectable被声明为:

And the jQuery selectable is declared as:

<script>
    $(function() {
        $("#select-image").selectable({
            selected: function( event, ui ) { 
                var $variable = $('.ui-selected').innerHTML; 
                console.log($variable);
            }
        });
    });
</script>

事件发生在列表项被选中后,在它输出到浏览器控制台的示例中。然而输出是未定义的。选择器 $('。ui-selected')。是正确的,因为它显示为浏览器控制台中的对象。

An event takes place after a list item has been selected, in the example it outputs to the browser console. The output however is "undefined." The selector $('.ui-selected'). is correct as it shows as an object in the browser's console. Where am I going wrong?

推荐答案

尝试

.text() .html()而不是 .innerHTML

这篇关于如何获得可选jQuery元素的innerHTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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