Showing posts with label web. Show all posts
Showing posts with label web. Show all posts

2009-04-11

动态创建 style 节点

在 IE 中 DOM 方式创建页面内 style 节点有点问题~ (创建出来的东西是不能修改内容的)
可用 document.createStyleSheet() 来解决:

// create style node
var _styleNode = _(u.STYLE_ID);
if (!_styleNode) {
 if (/*@cc_on!@*/0) { // is IE
  var ss = document.createStyleSheet();
  ss.cssText = _defaultStyleText;
  _styleNode = ss.owningElement; // the style node just created
  _styleNode.id = u.STYLE_ID;
 } else { // other browsers
  _styleNode = document.createElement("style");
  _styleNode.id = u.STYLE_ID;
  _styleNode.type = "text/css";
  _styleNode.innerHTML = _defaultStyleText;
  var head = document.getElementsByTagName("head")[0] || document.body;
  head.appendChild(_styleNode);
 }
}

另外,对于 link 引入 css 可用:
document.createStyleSheet("style.css");
对应:
var style = document.createElement("link");
style.href = "style.css";
style.rel = "stylesheet";
style.type = "text/css";
document.getElementsByTagName('head')[0].appendChild(style);

//EOF Read More...

2008-12-10

struts 配置文件中元素的順序

今天才發現原來 struts 配置文件中元素之間的順序是有要求的。

controller 放在 message-resources 之前會報錯,雖然程序能夠正常運行,但在加載的時候會報一個“配置文件解析錯誤”。

看來順序還是不能變~

//EOF Read More...

2008-12-07

ASP.NET TreeView check childs/parents

給 ASP.NET 的 TreeView 寫了一個掛件,主要功能就是在 TreeView 是 ShowCheckBox 模式的時候,當勾選某個節點時能自動的勾選這個節點相關的所有父節點,以及勾選、反勾選這個節點的所有子節點。

功能很簡單純 javascript 實現:

/*************************************************************************
 * change the tree view node's child nodes check-state, when check
 * this node.
 *
 *   NOTE: for ASP.NET TreeView
 *
 * @author h_Davy
 * @version 2008-12-5
 *************************************************************************/

/**
 * check the tree node's childs with this checkbox's stats
 *
 * @param chk   the check box element
 *
 * @private
 */
function _checkTreeChilds(chk)
{
    var childId = chk.id.replace('CheckBox', 'Nodes');
    var child = document.getElementById(childId);
    if (child) {
        var chks = child.getElementsByTagName('input');
        for (var i in chks) {
            if (chks[i].type == "checkbox") {
                chks[i].checked = chk.checked;
            }
        }
    }
}

/**
 * find out the checkbox-node's parent node's checkbox id
 *
 * @param chk       the check box element
 * @param treeView  the treeView element
 *
 * @return  the parent node checkbox id
 *
 * @private
 */
function _findTreeParentId(chk, treeView)
{
    if (!chk) return null;
    var tmpElm = chk.parentNode;
    for(;;) {
        if (tmpElm.tagName == "TABLE") {
            return tmpElm.parentNode.id.replace('Nodes', 'CheckBox');
        } else {
        // go up to find out the parent node, until touch the treeview
            tmpElm = tmpElm.parentNode;
            if (tmpElm == treeView) return null;
        }
    }
    return null;
}

/**
 * check the tree node's parent w this checkbox is checked
 *
 * @param chk   the check box element
 * @param treeView  the treeView element
 *
 * @private
 */
function _checkTreeParent(chk, treeView)
{
    if (!chk.checked) return;
    var tmpChk;
    var parentId = _findTreeParentId(chk);
    for(;;) {
        if (!parentId) return;
        if (chk.checked) {
            tmpChk = document.getElementById(parentId);
            if (!tmpChk || tmpChk == treeView) return;
            tmpChk.checked = true;
        }
        parentId = _findTreeParentId(tmpChk, treeView);
    }
}

/**
 * use this bind to a tree view
 *
 * @param id    the tree view's id (NOTE: it's the HTML node id, not .NET page server id)
 */
function bindCheckEvent(id) {
    var treeView = document.getElementById(id);
    var chks = treeView.getElementsByTagName('input');
    for(var i in chks) {
        if (chks[i].type == "checkbox") {
            chks[i].onclick = function() {
                _checkTreeChilds(this);
                _checkTreeParent(this, treeView);
            };
        }
    }
}

// -- EOF --

使用方法,在要使用的頁面導入以上代碼后,在頁面結尾處加上:
<script type="text/javascript">

bindCheckEvent('TreeView1');
// 這里的 'TreeView1' 就是那個TreeView的ID
// !!!注意:這里的ID指的是最終生成的HTML頁面中的ID,
//                 如果你的TreeView是在某個使用了模板頁的內容頁里面的話,
//                 就有可能是 'ctl00_ContentPlaceHolder1_TreeView1' 了。

</script>

//EOF Read More...

2008-11-30

Linux 中使用NetBeans部署、运行Web应用要注意目录权限设置

使用的是 tomcat
要注意以下几个目录的权限要当前用户可写

$CATALINA_HOME/conf/Catalina/localhost/
$CATALINA_HOME/webapps/
$CATALINA_HOME/work/Catalina/localhost/
$CATALINA_HOME/temp/

否则,有可能会出现无法写入部署目录而部署失败:

Failed to deploy application at context path /xxx

另外,还要注意
$CATALINA_HOME/bin/
下几个.sh文件的当前用户执行权限,不然tomcat都无法运行。

//EOF Read More...

2008-11-02

javascript 中判断是否为IE的技巧

利用 IE 中 jscript/javascript 的“条件编译”
条件编译:
/*@cc_on, @if, @elif, @else, @end, @*/
如:

/*@cc_on
   @if (@_win32)
      document.write("操作系统是32位windows。浏览器是IE。");
   @else
      document.write("操作系统不是32位windows。浏览器是IE。"); // 这个是不会输出的
   @end
@*/
技巧:
    if (!/*@cc_on!@*/0) { //if not IE
        //Firefox2、Firefox3、Safari3.1+、Opera9.6+ support 
    } else {
        //IE6、IE7 support 
    }

//EOF Read More...

2008-10-25

mono+mysql 出现 EntryPointNotFoundException: CreateSemaphore

今天试着在 Mono 中使用 mySql 的连接驱动 "MySql.Data.dll" 时出现异常:

System.EntryPointNotFoundException: CreateSemaphore
at (wrapper managed-to-native) MySql.Data.Common.Semaphore:CreateSemaphore (MySql.Data.Common.SECURITY_ATTRIBUTES&,int,int,string)
at MySql.Data.Common.Semaphore..ctor (Int32 initialCount, Int32 maximumCount) [0x00000]
at (wrapper remoting-invoke-with-check) MySql.Data.Common.Semaphore:.ctor (int,int)
at MySql.Data.MySqlClient.MySqlPool..ctor (MySql.Data.MySqlClient.MySqlConnectionString settings) [0x00000]
at MySql.Data.MySqlClient.MySqlPoolManager.GetPool (MySql.Data.MySqlClient.MySqlConnectionString settings) [0x00000]
at MySql.Data.MySqlClient.MySqlConnection.Open () [0x00000]
google 后发现 似乎时需要在连接字符串中设置 "Pooling=false"
private const string CONNECTION_STRING = "server={0};database={1};uid={2};pwd={3};Pooling=false;";
这样就正常了。
原因还不清楚……

//EOF Read More...

2008-10-08

DIV+CSS 布局时要注意的

左右浮动分栏布局时要记得清除浮动,否则下面的东西会上来哦!
在一行的浮动,之后不需要浮动的时候,记得在中间加上一个清除浮动层:

<div style="clear:both;line-height:0;height:0;font-size:0;"></div>
或:
.clear {clear:both;line-height:0;height:0;font-size:0;}
...
<div class="clear"></div>

例:
<?xml version="1.0" encoding="UTF-8" ?>
<!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" xml:lang="en" lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>双栏</title>
<style type="text/css">

body {
    text-align: center;
}

#body {
    text-align: left;
    width: 95%;
    margin: 0pt auto;
    min-width: 640px; /* IE6 不支持 */
}

#header {
    background-color: #def;
}

#content {
    
}

.left {
    float: left;
    width: 20%;
}

.right {
    float: left;
    width: 80%;
}

#foot {
    font-size: .8em;
    color: #999;
    text-align: center;
}

#header, #content, #foot {
}

p, h1 {
    margin: 0pt;
    padding: 5pt;
}

*, body {
    font-family: "Verdana", Geneva, Sans-Serif;
    /*font-size: 10pt;*/
}

</style>
<script type="text/javascript">

</script>
    </head>
    <body>
<div id="body">
        <div id="header">
            <h1>Header</h1>
            <p>this is the header</p>
        </div>
        <div id="content">
            <div class="left">
                <p>Left</p>
                <p>Left</p>
                <p>Left</p>
                <p>Left</p>
                <p>Left</p>
                <p>Left</p>
                <p>Left</p>
                Left
            </div>
            <div class="right">
                <p>Right</p>
                <p>Right</p>
                <p>Right</p>
                Right<br />
                Right<br />
                Right<br />
            </div>
        </div>
        <!-- 去掉下面这行试试 -->
        <div style="clear:both;line-height:0;height:0;font-size:0;"></div>
        <div id="foot">
            Copyright &copy; 2008, h_Davy; Powered by: VIM;
        </div>
</div>
    </body>
</html>

//EOF Read More...

2008-03-05

absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved

有一段时间没搞JSP了,今天用了标准标签库。奇怪,竟然会出现如下错误:

The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved

以前一直是正常的啊,探求了半天都未果。
(jstl.jar, standard.jar 我是放在WEB-INF/lib中的,以前这样做一直都OK啊!)
后来突发奇想,将这两个文件移到Tomcat的 shared/lib 中,然后重启那只笨猫,竟然OK了……
这个真的是诡异了,竟然在 WEB-INF/lib 中就找不到??
(其实WEB-INF/lib中我还有几个库也能找到啊!怎么就是标签库的就找不到呢?)

//EOF Read More...

2008-02-01

ScribeFire 中添加 <code> 标签支持

Scribefire具体安装在 <firefox home path>/extensions/ 下的哪个目录可以在 extensions.rdf 文件中找到(搜索 "ScribeFire" 即可),以下文件操作的根目录均为 Scribefire 的安装目录。

1. 自定义 <code> style
文件 /chrome/skin/blank.css 中添加:
code {
  display: block;
  font-size: 110%;
  margin: 5px;
  margin-left: 1.3em;
  padding: 3px;
  padding-left:  10px;
  background: #eee;
  border: 1px solid #ccc;
  border-left: 3px solid #ccc;
}


2. 操作界面外观
文件 /chrome/skin/toolbar/toolbar-code.png
(自己作的“<code>”按钮图片)

文件 /chrome/skin/overlay.css 中设置按钮外观图片
#code-button {
  list-style-image: url(chrome://performancing/skin/toolbar/toolbar-code.png);
}


3. 界面、事件关联

文件 /chrome/content/editor.xul 中:
 1) 按钮事件关联:
<command id="cmd_blockquote" oncommand="performancingMidas.blockquote()"/>
下依葫芦画瓢之:
<command id="cmd_code" oncommand="performancingMidas.code()"/>

 2) 按钮布局:
<toolbarbutton id="blockquote-button" command="cmd_blockquote" tooltiptext="&performancing.editor.bar.quote.tt;"/>
下依葫芦画瓢之:
<toolbarbutton id="code-button" command="cmd_code" tooltiptext="&performancing.editor.bar.code.tt;"/>


文件 /chrome/content/midas.js 中定义事件响应,分别在:
performancingMidas.blockquote = function(){
...
}

case "blockquote":
...

case "blockquote":
...

下依葫芦画瓢之。


文件 /chrome/content/locale-default/overlay.dtd 中定义 tooltips,在
<!ENTITY performancing.editor.bar.quote.tt "Quote">
下依葫芦画瓢之:
<!ENTITY performancing.editor.bar.code.tt "Code">

又做了一件无聊之事~~

//EOF Read More...

2007-05-14

Parse error: unexpected $end in xxx.php

"Parse error: syntax error, unexpected $end in xxx.php on line 1517"

出现这么一条莫名其妙的错误,1517行又是文件的末尾,真是莫明其妙。
其实,出现这种错误大多是由于文件中不匹配的 括号("()","{}")特别是掉了某个结束括号 引发的。

仔细巡查文档,发现原来在删除一段代码块时多删除了一行(那一行就是一个"}"符号)所致。

所幸,我写的代码格式还算规范,加上使用了VIM这种优秀的编辑器,这样我才能这么快的找到问题所在。

所以说嘛,书写规范格式的代码 是很有必要的!
要不然,就只有通过某种优秀的代码编辑器在成堆的代码中艰难的苦苦探寻才能找到找出问题了。:)
//EOF Read More...

2007-04-21

新版bloger模板设置[3]

这两天才发现新的bloger模板中有一个“Lables”模块,实现的就是那些分类的功能。
不过如果你的Bloger中有很多Lables的话,会出现一大版……影响美观啊~
于是我小改一下(添加 显示/隐藏 功能):
修改后Lables模块如下:

<b:widget id='Label1' locked='false' title='Labels' type='Label'>
<b:includable id='main'>
<b:if cond='data:title'>
<h2 onclick="NodeExpand('lable_list');" style="cursor:pointer;"><span id="mk1">&gt;</span><span id="mk2" style="display:none;">V</span> <data:title/></h2>
</b:if>
<div class='widget-content' id="lable_list" style="display:none;">
<ul>
<b:loop values='data:labels' var='label'>
<li>
<b:if cond='data:blog.url == data:label.url'>
<data:label.name/>
<b:else/>
<a expr:href='data:label.url'><data:label.name/></a>
</b:if>
(<data:label.count/>)
</li>
</b:loop>
</ul>

<b:include name='quickedit'/>
</div>
</b:includable>
</b:widget>

还要在Bloger的模板中添加一个Javascript模块,添加内容如下:
<script language=javascript type=text/javascript>
function NodeExpand(divName) {
objDiv = document.getElementById(divName);
objMark1 = this.document.getElementById('mk1');
objMark2 = this.document.getElementById('mk2');
if (objDiv) {
if (objDiv.style.display == "block") {
objDiv.style.display = "none";
objMark1.style.display = "";
objMark2.style.display = "none";
} else {
objDiv.style.display = "block";
objMark1.style.display = "none";
objMark2.style.display = "";
}
}
}
</script>


还有怎么让那些labels不要显示在一条长列里面呢,模板中添加如下style:
#lable_list ul{list-style:none;}
#lable_list li{float:left;width:100px;}

规定lable_list中每列只占用100px宽,以及横向排列。


BTW: 开始那个手形光标把我搞晕了,很久以前记得应该是 cursor:hand; 的,结果这样竟然无效!?
后来google了才发现原来 hand 是M$的标准,W3C 标准应该用 cursor:pointer; !!
(哎~ M$ 太恶劣了,毒害了一代人啊!)
//EOF Read More...