Home > Backend Development > PHP Tutorial > thinkPHP中Html模板标签怎么用

thinkPHP中Html模板标签怎么用

PHPz
Release: 2020-06-24 11:30:36
Original
1751 people have browsed it

thinkPHP中Html模板标签怎么用

thinkPHP的Html模板标签怎么用?

如果我们现在需要一个select下拉菜单项,那么在ThinkPHP中我们可以这样做

注意:在使用如等标签之前,必须要引入TP的标签库:

如果我们现在需要一个select下拉菜单项,那么在ThinkPHP中我们可以这样做。

1、在Action控制器的方法中获取数据,举例如下:

代码如下:

public function mylist(){
$user = new Model(‘User');
$list = $user->getField(‘id,username');
$this->assign(‘users',$list);
$this->display();
}
Copy after login

2、在模板页面中导入标签库并写如下代码即可

代码如下:

<tagLib name="html" />
<html:select name="uid" options="users" first="请选择用户" change="alert(‘Hello&#39;)"/>
Copy after login

这样我们只用了一个简单的标签就实现了下面的功能:(编译后的HTML代码)

代码如下:

<select id="" name="uid" onchange="alert(‘Hello&#39;)" ondblclick="" class="">
<option value="">请选择用户</option>
<option value="1″>no1</option>
<option value="2″>no2</option>
<option value="3″>no3</option>
<option value="4″>no4</option>
</select>
Copy after login

更多相关知识,请访问PHP中文网

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template