在view目录下创建Index_aaa.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>select</title>
</head>
<body>
<tagLib name="html"/>
<html:select options="address" selected="sh" values="address"/>
</body>
</html>
在IndexController.class.php里面编写函数
public function aaa(){
$this->assign("address",["sh"=> "上海","天津","北京","郑州"]);
$this->display();
}
修改此文件可以编写标签库
把输出的几项全部改为val即可解决values='0'
的问题,让values的值等于option的值
编写新的标签
'ms'=>array('attr'=>'id,name,options,selected','close'=>0)
<html:ms id="aa" name="uu" options="address" selected="北京"/><br>
修改后的代码selected的值可以随便写即可
public function _ms($tag) {
$name = $tag['name'];
$options = $tag['options'];
$id = $tag['id'];
$selected = $tag['selected'];
$parseStr = '<select id="'.$id.'" name="'.$name.'" >';
$parseStr .='<?php foreach($'.$options.' as $val) { ?>';
$parseStr .='<?php if("'.$selected.'"==$val) { ?>';
$parseStr .= '<option selected="selected" value="<?php echo $val ?>"><?php echo $val ?></option>';
$parseStr .= '<?php } else { ?><option value="<?php echo $val ?>"><?php echo $val ?></option>';
$parseStr .= '<?php } ?>';
$parseStr .= '<?php } ?>';
$parseStr .= '</select>';
return $parseStr;
}
可以根据分配的值来确定selected
public function _ms($tag) {
$name = $tag['name'];
$options = $tag['options'];
$id = $tag['id'];
$selected = $tag['selected'];
$parseStr = '<select id="'.$id.'" name="'.$name.'" >';
$parseStr .='<?php foreach($'.$options.' as $val) { ?>';
/* $parseStr .='<?php if("'.$selected.'"==$val) { ?>';*///selected的值可以随便写
$parseStr .='<?php if($'.$selected.'==$val) { ?>';//值可以先分配再写
$parseStr .= '<option selected="selected" value="<?php echo $val ?>"><?php echo $val ?></option>';
$parseStr .= '<?php } else { ?><option value="<?php echo $val ?>"><?php echo $val ?></option>';
$parseStr .= '<?php } ?>';
$parseStr .= '<?php } ?>';
$parseStr .= '</select>';
return $parseStr;
}
public function aaa(){
$this->assign("address",["上海","天津","北京","郑州"]);
$this->assign("sh","天津");
$this->display();
}
<tagLib name="html"/>
<html:ms id="aa" name="uu" options="address" selected="sh"/><br>
用框架本身带的也可以实现
把红线处的$key修改为$val用分配变量的方式也可以实现selected,系统自带的稍加修改,但是值不可以随便写在selected后
public function _select($tag) {
$name = $tag['name'];
$options = $tag['options'];
$values = $tag['values'];
$output = $tag['output'];
$multiple = $tag['multiple'];
$id = $tag['id'];
$size = $tag['size'];
$first = $tag['first'];
$selected = $tag['selected'];
$style = $tag['style'];
$ondblclick = $tag['dblclick'];
$onchange = $tag['change'];
if(!empty($multiple)) {
$parseStr = '<select id="'.$id.'" name="'.$name.'" ondblclick="'.$ondblclick.'" onchange="'.$onchange.'" multiple="multiple" class="'.$style.'" size="'.$size.'" >';
}else {
$parseStr = '<select id="'.$id.'" name="'.$name.'" onchange="'.$onchange.'" ondblclick="'.$ondblclick.'" class="'.$style.'" >';
}
if(!empty($first)) {
$parseStr .= '<option value="" >'.$first.'</option>';
}
if(!empty($options)) {
$parseStr .= '<?php foreach($'.$options.' as $key=>$val) { ?>';
if(!empty($selected)) {
$parseStr .= '<?php if(!empty($'.$selected.') && ($'.$selected.' == $val || in_array($key,$'.$selected.'))) { ?>';
$parseStr .= '<option selected="selected" value="<?php echo $val ?>"><?php echo $val ?></option>';
$parseStr .= '<?php }else { ?><option value="<?php echo $val ?>"><?php echo $val ?></option>';
$parseStr .= '<?php } ?>';
}else {
$parseStr .= '<option value="<?php echo $val ?>"><?php echo $val ?></option>';
}
$parseStr .= '<?php } ?>';
}else if(!empty($values)) {
$parseStr .= '<?php for($i=0;$i<count($'.$values.');$i++) { ?>';
if(!empty($selected)) {
$parseStr .= '<?php if(isset($'.$selected.') && ((is_string($'.$selected.') && $'.$selected.' == $'.$values.'[$i]) || (is_array($'.$selected.') && in_array($'.$values.'[$i],$'.$selected.')))) { ?>';
$parseStr .= '<option selected="selected" value="<?php echo $'.$values.'[$i] ?>"><?php echo $'.$output.'[$i] ?></option>';
$parseStr .= '<?php }else { ?><option value="<?php echo $'.$values.'[$i] ?>"><?php echo $'.$output.'[$i] ?></option>';
$parseStr .= '<?php } ?>';
}else {
$parseStr .= '<option value="<?php echo $'.$values.'[$i] ?>"><?php echo $'.$output.'[$i] ?></option>';
}
$parseStr .= '<?php } ?>';
}
$parseStr .= '</select>';
return $parseStr;
}
引入ueditor放在js里面修改ueditor.config.js为如下的代码
window.UEDITOR_HOME_URL = "/Public/js/ueditor/";
thinkphp里面放百度编辑器
$parseStr = '<script id="container" name="content" type="text/plain">这里写你的初始化内容</script><script type="text/javascript" src="__ROOT__/Public/js/ueditor/ueditor.config.js"></script><script type="text/javascript" src="__ROOT__/Public/js/ueditor/ueditor.all.js"></script><script type="text/javascript"> var ue = UE.getEditor("container",{emotionLocalization:true,lang:"zh-cn",initialFrameWidth:"80%",initialFrameHeight:320,textarea:"content",initialContent:"欢迎留言!", autoClearinitialContent:true}); </script>';
然后在Index_aaa.html 里面编写要显示的代码
<tagLib name="html"/>
<html:editor type="UEDITOR"></html:editor>