二次開發第一天


哎,人比較懶,邊玩邊做吧,第一天構思欄目構架很繁瑣,發呆了好幾天,花了一個小時解決了一個搜索,一點一點記錄下自己的過程吧

<form name="search" method="get" action="{APP_PATH}index.php" target="_blank">    
<div class="option" onClick="wValDisp('h','1');"><span id="wn_h">資訊</span></div>

<div class="sbox">
<input type="hidden" name="m" value="search"/>
<input type="hidden" name="c" value="index"/>
<input type="hidden" name="a" value="init"/>
<input type="hidden" name="typeid" value="1" id="typeid"/>
<input type="hidden" name="siteid" value="{$siteid}" id="siteid"/>
<input type="text" class="text" name="q" id="q"/>
</div>
<div class="sbtn"><input type="submit" value="搜" style="letter-spacing:-1px;" /></div>
<div id="sbArea_h" style="display:none;">
{php
$j=0}
{php
$search_model = getcache('search_model_'.$siteid, 'search');}
{loop
$search_model $k=>$v}
{php
$j++;}
<a target="_self" href="javascript:wValChg('{$j}','h');" onFocus="blur();"><div class="dselObj" id="id="wv_h_{$j}">{$v['name']}</div></a>{if $j != count($search_model)}<span></br></span>{/if}
{/loop}
{php unset(
$j);}

</div>
</form>
 <input type="hidden" name="typeid" value="1" id="typeid"/> 這里是為了有一個默認選擇搜索的類型
搜索需要引用<script language="JavaScript" src="{JS_PATH}js/fun_index.js"></script> 這個JS
//39健康搜索
function getNavigatorType(){
if(navigator.appName == "Microsoft Internet Explorer")
return 1;
else if(navigator.appName == "Netscape")
return 2;
else
return 0;
}

function getObject(objectId){
// checkW3C DOM, then MSIE 4, then NN 4.
if(document.getElementById && document.getElementById(objectId)){
return document.getElementById(objectId);
}
else if (document.all && document.all(objectId)){
return document.all(objectId); // IE4,5.0
}else if (document.layers && document.layers[objectId]){
return document.layers[objectId]; // Netscape 4.x
}else{
return false;
}
}

function wValChg(idx,sts){
//var s = "http://www.yikao163.com/";
if(idx == "1") {getObject("wn_"+ sts +"").innerHTML = "資訊"; getObject("typeid").value="1";}
if(idx == "2") {getObject("wn_"+ sts +"").innerHTML = "圖片"; getObject("typeid").value="3";}
if(idx == "3") {getObject("wn_"+ sts +"").innerHTML = "下載"; getObject("typeid").value="2";}
if(idx == "4") {getObject("wn_"+ sts +"").innerHTML = "專題"; getObject("typeid").value="52";}
//m=search&c=index&a=init&typeid=1&siteid=1&q=測試一下
/*if(sts == "h"){
document.search.action = s + idx +".aspx";
}
*/
getObject(
"sbArea_"+ sts +"").style.display = "none";
}

function wValDisp(sts,idx){
if(getObject("sbArea_"+ sts +"").style.display == "none"){
getObject(
"sbArea_"+ sts +"").style.display = "";
}
else{
getObject(
"sbArea_"+ sts +"").style.display = "none";
}
}

function setSelBox(event){
var _event;
switch (getNavigatorType()) {
case 1 : // IE
_event = window.event;
node
= _event.srcElement;
nodeName
= _event.srcElement.className;
break;
case 2 : // Netscape
_event = event;
node
= _event.target;
nodeName
= _event.target.className;
break;
default :
nodeName
= "None";
break;
}
if(nodeName == "dselObj"){

}
else{
try{
document.getElementById(
"sbArea_h").style.display = "none";
}
catch(e){}
}
}
document.onmousedown
= setSelBox;

//顯示與隱藏列表
function showList(id,num){
if(num == 1){
document.getElementById(id).style.display
= "block";
}
else{
document.getElementById(id).style.display
= "none";
}
}

//選項卡切換
function showTab(n1,n2){
var h=document.getElementById("Tab"+n1).getElementsByTagName("h2");
var d=document.getElementById("Tab"+n1).getElementsByTagName("div");
for(var i=0;i<h.length;i++){
if(n2-1==i){
h[i].className
+=" up";
d[i].className
+=" block";
}
else {
h[i].className
=" ";
d[i].className
=" ";
}
}
}

//設為首頁&加入收藏
var isIE=(document.all&&document.getElementById&&!window.opera)?true:false;
var isMozilla=(!document.all&&document.getElementById&&!window.opera)?true:false;
var isOpera=(window.opera)?true:false;
var seturl='url(#default#homepage)';
var weburl=window.location.href;
var webname=document.title;

function myhomepage() {
if(isMozilla){
try {netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");}
catch (e){alert("此操作被瀏覽器拒絕!\n請在瀏覽器地址欄輸入“about:config”並回車\n然后將[signed.applets.codebase_principal_support]設置為'true'");}
var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
prefs.setCharPref(
'browser.startup.homepage',weburl);
}
if(isIE){
this.homepage.style.behavior=seturl;this.homepage.sethomepage(weburl);
}
}

function addfavorite()
{

if(isMozilla){
if (document.all){ window.external.addFavorite(weburl,webname);}
else if (window.sidebar){ window.sidebar.addPanel(webname, weburl,"");}
}
if(isIE){window.external.AddFavorite(weburl, webname);}
}

//flash 浮標必要腳本
function insertFlash(elm, url, w, h, id) {
if (!document.getElementById(elm)) return;
var str = '';
str
+= '<embed width="'+ w +'" height="'+ h +'" src="'+ url +'" quality="autohigh" wmode="opaque" type="application/x-shockwave-flash" plugspace="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" id='+id+'></embed>';
document.getElementById(elm).innerHTML
= str;
}

function insertFlash1(elm, url, w, h, id) {
if (!document.getElementById(elm)) return;
var str = '';
str
+= '<embed width="'+ w +'" height="'+ h +'" src="'+ url +'" quality="autohigh" wmode="transparent" type="application/x-shockwave-flash" plugspace="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" id='+id+'></embed>';
document.getElementById(elm).innerHTML
= str;
}


//** Featured Content Slider script- (c) Dynamic Drive DHTML code library: http://www.dynamicdrive.com.
var featuredcontentslider={
enablepersist:
true, //persist to last content viewed when returning to page?
settingcaches: {}, //object to cache "setting" object of each script instance

buildcontentdivs:
function(setting){
var alldivs=document.getElementById(setting.id).getElementsByTagName("div")
for (var i=0; i<alldivs.length; i++){
if (this.css(alldivs[i], "contentdiv", "check")){ //check for DIVs with class "contentdiv"
setting.contentdivs.push(alldivs[i])
alldivs[i].style.display
="none" //collapse all content DIVs to begin with
}
}
},

buildpaginate:
function(setting){
this.buildcontentdivs(setting)
var sliderdiv=document.getElementById(setting.id)
var pdiv=document.getElementById("paginate-"+setting.id)
var toc=setting.toc
var pdivlinks=pdiv.getElementsByTagName("a")
var toclinkscount=0 //var to keep track of actual # of toc links
for (var i=0; i<pdivlinks.length; i++){
if (this.css(pdivlinks[i], "toc", "check")){
if (toclinkscount>setting.contentdivs.length-1){ //if this toc link is out of range (user defined more toc links then there are contents)
pdivlinks[i].style.display="none" //hide this toc link
continue
}
pdivlinks[i].setAttribute(
"rel", ++toclinkscount) //store page number inside toc link
pdivlinks[i][setting.revealtype]=function(){
featuredcontentslider.turnpage(setting,
this.getAttribute("rel"))
return false
}
setting.toclinks.push(pdivlinks[i])
}
else if (this.css(pdivlinks[i], "prev", "check") || this.css(pdivlinks[i], "next", "check")){ //check for links with class "prev" or "next"
pdivlinks[i].onclick=function(){
featuredcontentslider.turnpage(setting,
this.className)
return false
}
}
}
this.turnpage(setting, setting.currentpage, true)
if (setting.autorotate[0]){ //if auto rotate enabled
pdiv[setting.revealtype]=function(){
featuredcontentslider.cleartimer(setting, window[
"fcsautorun"+setting.id])
}
sliderdiv[
"onclick"]=function(){ //stop content slider when slides themselves are clicked on
featuredcontentslider.cleartimer(setting, window["fcsautorun"+setting.id])
}
setting.autorotate[
1]=setting.autorotate[1]+(1/setting.enablefade[1]*50) //add time to run fade animation (roughly) to delay between rotation
this.autorotate(setting)
}
},

urlparamselect:
function(fcsid){
var result=window.location.search.match(new RegExp(fcsid+"=(\\d+)", "i")) //check for "?featuredcontentsliderid=2" in URL
return (result==null)? null : parseInt(RegExp.$1) //returns null or index, where index (int) is the selected tab's index
},

turnpage:
function(setting, thepage, autocall){
var currentpage=setting.currentpage //current page # before change
var totalpages=setting.contentdivs.length
var turntopage=(/prev/i.test(thepage))? currentpage-1 : (/next/i.test(thepage))? currentpage+1 : parseInt(thepage)
turntopage
=(turntopage<1)? totalpages : (turntopage>totalpages)? 1 : turntopage //test for out of bound and adjust
if (turntopage==setting.currentpage && typeof autocall=="undefined") //if a pagination link is clicked on repeatedly
return
setting.currentpage
=turntopage
// setting.contentdivs[turntopage-1].style.zIndex=++setting.topzindex
this.cleartimer(setting, window["fcsfade"+setting.id])
setting.cacheprevpage
=setting.prevpage
if (setting.enablefade[0]==true){
setting.curopacity
=0
this.fadeup(setting)
}
if (setting.enablefade[0]==false){ //if fade is disabled, fire onChange event immediately (verus after fade is complete)
setting.contentdivs[setting.prevpage-1].style.display="none" //collapse last content div shown (it was set to "block")
setting.onChange(setting.prevpage, setting.currentpage)
}
setting.contentdivs[turntopage
-1].style.visibility="visible"
setting.contentdivs[turntopage
-1].style.display="block"
if (setting.prevpage<=setting.toclinks.length) //make sure pagination link exists (may not if manually defined via "markup", and user omitted)
this.css(setting.toclinks[setting.prevpage-1], "selected", "remove")
if (turntopage<=setting.toclinks.length) //make sure pagination link exists (may not if manually defined via "markup", and user omitted)
this.css(setting.toclinks[turntopage-1], "selected", "add")
setting.prevpage
=turntopage
if (this.enablepersist)
this.setCookie("fcspersist"+setting.id, turntopage)
},

setopacity:
function(setting, value){ //Sets the opacity of targetobject based on the passed in value setting (0 to 1 and in between)
var targetobject=setting.contentdivs[setting.currentpage-1]
if (targetobject.filters && targetobject.filters[0]){ //IE syntax
if (typeof targetobject.filters[0].opacity=="number") //IE6
targetobject.filters[0].opacity=value*100
else //IE 5.5
targetobject.style.filter="alpha(opacity="+value*100+")"
}
else if (typeof targetobject.style.MozOpacity!="undefined") //Old Mozilla syntax
targetobject.style.MozOpacity=value
else if (typeof targetobject.style.opacity!="undefined") //Standard opacity syntax
targetobject.style.opacity=value
setting.curopacity
=value
},

fadeup:
function(setting){
if (setting.curopacity<1){
this.setopacity(setting, setting.curopacity+setting.enablefade[1])
window[
"fcsfade"+setting.id]=setTimeout(function(){featuredcontentslider.fadeup(setting)}, 50)
}
else{ //when fade is complete
if (setting.cacheprevpage!=setting.currentpage) //if previous content isn't the same as the current shown div (happens the first time the page loads/ script is run)
setting.contentdivs[setting.cacheprevpage-1].style.display="none" //collapse last content div shown (it was set to "block")
setting.onChange(setting.cacheprevpage, setting.currentpage)
}
},

cleartimer:
function(setting, timervar){
if (typeof timervar!="undefined"){
clearTimeout(timervar)
clearInterval(timervar)
if (setting.cacheprevpage!=setting.currentpage){ //if previous content isn't the same as the current shown div
setting.contentdivs[setting.cacheprevpage-1].style.display="none"
}
}
},

css:
function(el, targetclass, action){
var needle=new RegExp("(^|\\s+)"+targetclass+"($|\\s+)", "ig")
if (action=="check")
return needle.test(el.className)
else if (action=="remove")
el.className
=el.className.replace(needle, "")
else if (action=="add")
el.className
+=" "+targetclass
},

autorotate:
function(setting){
window[
"fcsautorun"+setting.id]=setInterval(function(){featuredcontentslider.turnpage(setting, "next")}, setting.autorotate[1])
},

getCookie:
function(Name){
var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
if (document.cookie.match(re)) //if cookie found
return document.cookie.match(re)[0].split("=")[1] //return its value
return null
},

setCookie:
function(name, value){
document.cookie
= name+"="+value

},

init:
function(setting){
var persistedpage=this.getCookie("fcspersist"+setting.id) || 1
var urlselectedpage=this.urlparamselect(setting.id) //returns null or index from: mypage.htm?featuredcontentsliderid=index
this.settingcaches[setting.id]=setting //cache "setting" object
setting.contentdivs=[]
setting.toclinks
=[]
// setting.topzindex=0
setting.currentpage=urlselectedpage || ((this.enablepersist)? persistedpage : 1)
setting.prevpage
=setting.currentpage
setting.revealtype
="on"+(setting.revealtype || "click")
setting.curopacity
=0
setting.onChange
=setting.onChange || function(){}
if (setting.contentsource[0]=="inline")
this.buildpaginate(setting)
}

}
View Code

 <div class="option" onClick="wValDisp('h','1');"><span id="wn_h">資訊</span></div>

<a  target="_self"  href="javascript:wValChg('{$j}','h');" onFocus="blur();"><div class="dselObj" id="id="wv_h_{$j}">{$v['name']}</div></a>{if $j != count($search_model)}<span></br></span>{/if}

這兩句要跟里面的JS對應起來

參考代碼

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Js特效:Js實現的下拉列表框效果--中國IT人才網!IT求職,IT招聘</title>
</head>
<style type="text/css">
*
{ margin:0; padding:0;}
body
{ font-size:12px; line-height:150%;}
td
{ height:22px; padding:6px;}
a
{font-size:12px; color:#000000; text-decoration:none;}
a:link
{color: #000000;}
a:visited
{color: #000000;}
a:hover
{text-decoration: underline; color:#000000;}
a:active
{color:#000000;}
img
{border:none;}
ul,li
{ list-style-type:none;}

.search
{ width:300px; margin:30px auto;}
.sel
{float:right;border:solid 1px #FFC128; height:18px;width:60px;overflow:hidden;margin-top:3px;}

.option
{width:50px;height:16px;padding:2px 0 0 6px;margin:0px 0 0 0px;color:#d78100;font-size:12px;line-height:14px;+line-height:16px;position:absolute;z-index:10;background:#fff url(http://images.qqyy.com/buttonbg.gif) no-repeat -645px -4px;cursor:pointer;}
#sbArea_h
{width:49px;font-size:14px;color:#d78100;padding:1px 0 1px 0px;margin:18px 0 0 0px;border:#f5a429 1px solid;position:absolute;z-index:20;background:#fff;}
#sbArea_h a
{float:left;color:#666; text-decoration:none;}
#sbArea_h a:hover
{color:#fff;background:#f90 url(http://images.qqyy.com/buttonbg.gif) no-repeat -625px -4px;}
#sbArea_h div
{float:left;width:43px;padding:2px 0 2px 5px;-padding:3px 0 0 5px;cursor:pointer;}
</style>
<script type="text/javascript">
function wValDisp(sts,idx)
{
if(getObject("sbArea_"+ sts +"").style.display == "none")
{
getObject(
"sbArea_"+ sts +"").style.display = "";
}
else
{
getObject(
"sbArea_"+ sts +"").style.display = "none";
}
}
function getObject(objectId)
{
// checkW3C DOM, then MSIE 4, then NN 4.
if(document.getElementById && document.getElementById(objectId))
{
return document.getElementById(objectId);
}
else if (document.all && document.all(objectId))
{
return document.all(objectId); // IE4,5.0
}
else if (document.layers && document.layers[objectId])
{
return document.layers[objectId]; // Netscape 4.x
}
else
{
return false;
}
}
function wValChg(idx,sts){
if(idx == "s") getObject("wn_"+ sts +"").innerHTML = "綜合";
if(idx == "h") getObject("wn_"+ sts +"").innerHTML = "人才";
if(idx == "j") getObject("wn_"+ sts +"").innerHTML = "職位";
if(idx == "z") getObject("wn_"+ sts +"").innerHTML = "資訊";
getObject(
"sbArea_"+ sts +"").style.display = "none";
}
function getNavigatorType()
{
if(navigator.appName == "Microsoft Internet Explorer")
return 1;
else if(navigator.appName == "Netscape")
return 2;
else
return 0;
}
function setSelBox(event)
{
var _event;
switch (getNavigatorType())
{
case 1 : // IE
_event = window.event;
node
= _event.srcElement;
nodeName
= _event.srcElement.className;
break;
case 2 : // Netscape
_event = event;
node
= _event.target;
nodeName
= _event.target.className;
break;
default :
nodeName
= "None";
break;
}
if(nodeName == "dselObj")
{

}
else
{
try
{
document.getElementById(
"sbArea_h").style.display = "none";
}
catch(e){}
}
}
document.onmousedown
= setSelBox;
</script>
<body>
<div class="search">
<div class="sel">
<input type="hidden" name="w" value="h"/>
<div class="option" onClick="wValDisp('h','web');"><span id="wn_h">綜合</span></div>
<div id="sbArea_h" style="display:none;">
<a target="_self" href="javascript:wValChg('s','h');" onFocus="blur();"><div class="dselObj" id="wv_h_0">綜合</div></a>
<a target="_self" href="javascript:wValChg('h','h');" onFocus="blur();"><div class="dselObj" id="wv_h_0">人才</div></a>
<a target="_self" href="javascript:wValChg('j','h');" onFocus="blur();"><div class="dselObj" id="wv_h_1">職位</div></a>
<a target="_self" href="javascript:wValChg('z','h');" onFocus="blur();"><div class="dselObj" id="wv_h_2">資訊</div></a>
</div>
</form>
</div>
</div>
</body>
</html>
View Code

注意JS里面的提交地址的變化,這里主要采用GET方式,post方式的話得要另外想辦法了



2.{php echo runhook('glogal_header')} {php echo runhook('glogal_menu')}這兩個跟后台設置是否顯示有關系

3.用到一些函數
  {$url}當前地址
  
  getcache是 讀取緩存文件的函數
  具體函數實現見phpcms\libs\functions\global.func.php中
  
/**
* 讀取緩存,默認為文件緩存,不加載緩存配置。
* @param string $name 緩存名稱
* @param $filepath 數據路徑(模塊名稱) caches/cache_$filepath/
* @param string $config 配置名稱
*/
function getcache($name, $filepath='', $type='file', $config='')

  就像{php $area_linkage = getcache(1,'linkage'); $area_data = $area_linkage[data];} <!-- 區域緩存 --> 就是讀取caches\caches_linkage\caches_data下面的區域緩存

  {str_cut($r[catname],12,"")}截取12個字符,漢字跟字母字符還有點區別的

  {url_par("areaid=$key",$url)} 格式化一般用作超鏈接后面的產生參數,例如<li><a class="i4" href="{url_par("areaid=$key",$url)}">{$val}</a></li>




注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
粤ICP备14056181号  © 2014-2020 ITdaan.com