如何获得课程名称? [英] How to get class names?

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

问题描述

嘿,我正在尝试动态获取下面脚本的类名.

Hey, I am trying to get the class names dynamically for the script below.

我有通过PHP创建的不同的类名,因此需要动态使用jQuery获得它们.

I have different class names that are created through PHP so need to get them using jQuery dynamically.

正如您在下面看到的那样,似乎有两个地方需要获取类名.目前,它是硬编码的(这些类称为结果"):

As you can see below, there seems to be 2 areas where I need to get the class name. At the moment it is hard coded (the classes are named 'result'):

1)var new_content = $(' #hiddenresult div.result :eq('+ page_index +')').clone();

1) var new_content = $('#hiddenresult div.result:eq('+page_index+')').clone();

2)var num_entries = $(' #hiddenresult div.result ').length;

2) var num_entries = $('#hiddenresult div.result').length;

所以,我希望jquery获得类名,而不是像下面这样对我进行硬编码.

so, I'd like jquery to get the class name instead of me just hard coding it in as seen below.

jQuery文件:

<script type="text/javascript">

        function pageselectCallback(page_index, jq){
        var new_content = $('#hiddenresult div.result:eq('+page_index+')').clone();
        $('#Searchresult').empty().append(new_content);
        return false;
    }

    /** 
     * Callback function for the AJAX content loader.
     */
    function initPagination() {
        var num_entries = $('#hiddenresult div.result').length;
        // Create pagination element
        $("#Pagination").pagination(num_entries, {
            num_edge_entries: 2,
            num_display_entries: 8,
            callback: pageselectCallback,
            items_per_page:1
        });
     }

    // Load HTML snippet with AJAX and insert it into the Hiddenresult element
    // When the HTML has loaded, call initPagination to paginate the elements        
    $(document).ready(function(){      
        initPagination();
    });
</script>

任何有关实施解决方案的帮助都将非常有用.谢谢

Any help on implementing a solution would be great. Thanks

推荐答案

如果我理解正确,那么无论给div的类是什么,您都希望代码能够工作. (但是会上一些课)

If i understand correctly you want your code to work regardless of the class that is given to the divs. (but some class will be given)

如果要使用

var new_content = $('#hiddenresult div[class]:eq('+page_index+')').clone();

var num_entries = $('#hiddenresult div[class]').length;

这意味着在#hiddenresult下找到定义了类属性的div(无论实际的类名是什么.)

which means find any div under #hiddenresult that has a class attribute defined (regardless of the actual class name..)

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

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