获取PHP中无序列表的所有列表项 [英] Getting all list items of an unordered list in PHP

查看:168
本文介绍了获取PHP中无序列表的所有列表项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这些标签云列表

<ul #id = "tag-cloud-list">
    <li class = "items">Music</li>
    <li class = "items">Lion</li>
    <li class = "items">Dwarf</li<
</ul>

那是由JQuery生成的.这里的项目是我将插入数据库的标签.现在我的问题是是否可以将所有<li>项目都放入ul中?并将它们放入PHP数组中?因为这些标签中的每一个都将插入数据库中.如果没有办法我可以使用php获取li项目,那么如何将这些列表项目插入数据库?因为我需要它们,因为它是某个项目或帖子的标签

That was generated by JQuery. The items here are tags that I will insert to the database. Now my question is it possible to get all <li> items inside the ul? and put them inside a PHP array? because each of these tags will be inserted in the database. if there's no way I can get a li items using php then how would Insert these list items into the database? because I needed them since it is tag to a certain item or post

推荐答案

您必须进行AJAX调用:

You have to make an AJAX call:

var lis = new Array();

// Iterate through the <li> items
$("#tag-cloud-list").children("li").each(function()
{
    lis.push($(this).text());
});

// Make AJAX call and set data to something like "Music::Lion::Dwarf"
$.ajax({
    url: "dostuff.php",
    type: "POST",
    data: { items: lis.join("::") },
    success: function() { alert("OK"); }
});

然后在PHP脚本中,使用

Then in the PHP script, use

$lis = $_POST['items'];
$liarray = explode("::", $lis);

检索li个项目的数组

这篇关于获取PHP中无序列表的所有列表项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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