当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 利用JavaScript创建功能强大的GUI(3)

Javascript
vml圆角矩形最简布局
DOM精简教程
[换皮肤程序]一个比较使用的脚本程序
JS中style属性
Google Suggest ;-) 基于js的动态下拉菜单
jQuery 1.0.2
PJ Blog插件-防刷新的在线播放器
使javascript也能包含文件
Dron右键菜单 v1.0
HTML里select的CSS样式的改变
仿Google和Windows Live的拖拽
"好玩的放大镜效果" 的另一种实现方法
xWin之JS版
bcastr2.0 通用的图片浏览器
addRule在firefox下的兼容写法
JS日历 推荐
用脚本调用样式的几种方法
不错的新闻标题颜色效果
用JavaScript获取网页中的js、css、Flash等文件
用js+xml自动生成表格的东西

Javascript 中的 利用JavaScript创建功能强大的GUI(3)


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 268 ::
收藏到网摘: n/a

function insert_link() {
var str = document.selection.createRange().text;
document.my_form.my_textarea.focus();
var my_link = prompt("Enter URL:","http://");
if (my_link != null) {
var sel = document.selection.createRange();
sel.text = "<a href=\"" + my_link + "\">" + str + "</a>";
}
return;
}

  第二个函数insert_link()与format_sel()是相同的,加上prompt(),它们可以使用户输入一个超文本链接的值。使用prompt()的结果,我们可以将选定的文本和代码组合起来,创建一个连接。有了这些函数,我们就可以为用户创建所有类型的界面。下面我们来看一个例子。

在CSS中使用系统颜色

  在网站上使用上面函数的最简单的方法就是在“bold”、“italic”、和“link”按钮的onclick事件处理程序中调用这些函数,但这不够刺激。由于我们使用了selection对象,把自己限定在了IE/Win平台上,我们就应该充分利用IE的特性,在CSS中使用用户定义的系统颜色,创建象我们在其他软件中看到的那样的动态按钮。下面我们首先来看看定义了工具栏、按钮、升起和按下二种按钮的状态的样式表。

#toolbar {
margin: 0;
padding: 0;
width: 262px;
background: buttonface;
border-top: 1px solid buttonhighlight;
border-left: 1px solid buttonhighlight;
border-bottom: 1px solid buttonshadow;
border-right: 1px solid buttonshadow;
text-align:right;
}

.button {
background: buttonface;
border: 1px solid buttonface;
margin: 1;
}

.raised {
border-top: 1px solid buttonhighlight;
border-left: 1px solid buttonhighlight;
border-bottom: 1px solid buttonshadow;
border-right: 1px solid buttonshadow;
background: buttonface;
margin: 1;
}

.pressed {
border-top: 1px solid buttonshadow;
border-left: 1px solid buttonshadow;
border-bottom: 1px solid buttonhighlight;
border-right: 1px solid buttonhighlight;
background: buttonface;
margin: 1;
}