根据列表项类别进行搜索 [英] Search based on list item class

查看:54
本文介绍了根据列表项类别进行搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

除了编写标记和CSS外,我对其他内容都不是很熟悉。

I'm not too familiar with anything beyond writing markup and CSS, and I have a question..

如果我有一个.html页面,其结构类似于

If I have one .html page with a structure like this:

<ul>
<li></li>
<li></li>
<li></li>
</ul>

现在让我们假设每个列表项都分配有一个类,但是该类不是唯一的,并且已多次使用。是否可以将基于某个类的所有列表项提取到另一个.html页面?例如,将所有具有红色类的列表项召集到名为red.html的页面,并将所有具有蓝色类的项召集到blue.html。

Now let's assume each of these list items has a class assigned to it, but the class is not unique, and is used multiple times. Is it possible to fetch all list items based on a certain class to another .html page? For example, summon all list items with class "red" to a page called red.html, and all items with class "blue" to blue.html.

用PHP或其他基本方法执行此操作的任何简单方法?

Is there any simple way to do this with PHP or another basic method?

任何输入都会受到赞赏。

Any input is appreciated.

推荐答案

让我们说这是您的html:

lets say that is your html:

<ul id="list">
<li class="red"></li>
<li class="blue"></li>
<li class="red"></li>

然后,您可以使用javascript来实现此目的,方法是获取所需的元素,然后使用ajax方法将其发送到所需的页面。

then you could accomplish this with javascript by grabbing the desired elements and then sending these using ajax method to desired page.

$(function(){

var elements = $('#list').children('.red');

$('#button').click(function(){  
    $.ajax({
        method: 'POST',
        url: 'somepage.php',
        data: elements,
        success: function(data) {
            $('#result').html(data);
      }
    });   
});

});

请注意,我在这里使用jQuery,在纯JavaScript中看起来会有所不同...希望这会有所帮助:)

Note that i'm using jQuery here, it would look differently in plain javascript... hope this helps :)

这篇关于根据列表项类别进行搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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