当前位置: 网学 > 编程文档 > PHP > 正文

QueryPath PHP 中的jQuery

来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 13/06/25
inciples behind QueryPath. Now let''s take a look at a larger example that exercises more of the QueryPath API.
A Longer Example
This example illustrates various core features of QueryPath.
In this example, we use some of the standard QueryPath functions (most of them implementing the jQuery interface) to build a new web page from scratch.
Each line of the code has been commented individually. The output from this is shown in a separate block beneath.
复制代码 代码如下:
<?php
/**
* Using QueryPath.
*
* This file contains an example of how QueryPath can be used
* to generate web pages.
* @package QueryPath
* @subpackage Examples
* @author M Butcher <matt@aleph-null.tv>
* @license LGPL The GNU Lesser GPL (LGPL) or an MIT-like license.
*/
// Require the QueryPath core.
require_once ''QueryPath/QueryPath.php'';
// Begin with an HTML stub document (XHTML, actually), and navigate to the title.
qp(QueryPath::HTML_STUB, ''title'')
// Add some text to the title
->text(''Example of QueryPath.'')
// Now look for the <body> element
->find('':root body'')
// Inside the body, add a title and paragraph.
->append(''<h1>This is a test page</h1><p>Test text</p>'')
// Now we select the paragraph we just created inside the body
->children(''p'')
// Add a ''class="some-class"'' attribute to the paragraph
->attr(''class'', ''some-class'')
// And add a style attribute, too, setting the background color.
->css(''background-color'', ''#eee'')
// Now go back to the paragraph again
->parent()
// Before the paragraph and the title, add an empty table.
->prepend(''<table id="my-table"></table>'')
// Now let''s go to the table...
->find(''#my-table'')
// Add a couple of empty rows
->append(''<tr></tr><tr></tr>'')
// select the rows (both at once)
->children()
// Add a CSS class to both rows
->addClass(''table-row'')
// Now just get the first row (at position 0)
->eq(0)
// Add a table header in the first row
->append(''<th>This is the header</th>'')
// Now go to the next row
->next()
// Add some data to this row
->append(''<td>This is the data</td>'')
// Write it all out as HTML
->writeHTML();
?>

The code above produces the following HTML:
复制代码 代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>
<title>Example of QueryPath.</title>
</head>
<body>
<table id="my-table">
<tr class="table-row"><th>This is the header</th></tr>
<tr class="table-row"><td>This is the data</td></tr>
</table>
<h1>This is a test page</h1>
<p class="some-class" style="background-color: #eee">Test text</p></body>
</h

网学推荐

免费论文

原创论文

浏览:
设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
湘ICP备09003080号