Search based on list item class

瘦欲@ 提交于 2020-01-03 04:35:09

问题


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

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

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

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.

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

Any input is appreciated.


回答1:


lets say that is your html:

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

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);
      }
    });   
});

});

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



来源:https://stackoverflow.com/questions/12548151/search-based-on-list-item-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!