几个网页中的小技巧!有时候还是挺有用的!
1、如何在Html里面创建后退按钮分别有按钮和图片两种
按钮:
<input type="button" value="Back" name="ClickBack" onclick=(history.back())>
或者
图片:
<img id="clickback" border="0" src="icons/icon5.gif" onclick=(history.back()) style="cursor:
hand">
2、如何在Html里面创建“添加到收藏夹”按钮
<input id="btnBookmark" type="button" value="Add To Favorites"
onclick="window.external.AddFavorite(location.href, document.title);">
3、如何在HTML里面创建关闭窗口按钮
private void Page_Load(object sender, System.EventArgs e)
{
this.Button1.Attributes.Add("OnClick", "window.close()")
}
OR
private void Button1_Click(object sender, System.EventArgs e) {
Response.Write("<script language='javascript'> { window.close() }</script>")
}
4、如何屏蔽客户端IE的右键功能
<script language="javascript">
document.onmousedown=disableclick
status="Right Click Disabled"
function disableclick(e) {
if( event.button==2 )
alert("对不起!右键在该页面不可使用!");
return false;
}
</script>
5、如何在IE的状态栏里显示当前时间
使用的js代码
function ShowTime()
{
var TimerKey
var now = new Date()
var Hours = now.getHours()
var Minutes = now.getMinutes()
var Seconds = now.getSeconds()
TimeDisplay.innerText = ((Hours > 12) ? Hours - 12 : Hours) + ((Minutes < 10) ? ":0" : ":") +
Minutes + ((Seconds < 10) ? ":0" : ":") + Seconds + ((Hours > 12) ? " PM" : " AM")
window.status = ((Hours > 12) ? Hours - 12 : Hours) + ((Minutes < 10) ? ":0" : ":") + Minutes +
((Seconds < 10) ? ":0" : ":") + Seconds + ((Hours > 12) ? " PM" : " AM")
TimerKey = setTimeout("ShowTime()",1000)
}
HTML中使用方法
<body onload=ShowTime()>就OK了!
6、如何在客户端得到ListBox中的值
使用的js代码:
function GetList(frm)
{
var result = ""
var newindex = 0
for (var i = 0; i < document.forms[0].L1.length; i++) {
if ( frm.L1.options[i].selected ) {
result += document.forms[0].L1.options[i].value + ", "
}
}
frm.txtResults.value = result
}
使用方法是:在指定名为L1的ListBox里面使用onChange="GetList(this.form)" !
觉得好就顶一下!