首页 | 源码下载 | 网站模板 | 网页特效 | 广告代码 | 网页素材 | 字体下载 | 书库 | 站长工具
会员投稿 投稿指南 RSS订阅
当前位置:主页>网络编程>Javascript教程>资讯:常用JavaScript代码6

常用JavaScript代码6

www.jz123.cn  2010-09-27   来源:   中国建站    责任编辑(袁袁)    我要投递新闻

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<style>
#hint{
width:198px;
border:1px solid #000000;
background:#99ff33;
position:absolute;
z-index:9;
padding:6px;
line-height:17px;
text-align:left;
top: 1520px;
}
</style>
<SCRIPT LANGUAGE="JavaScript">
<!--
function showme()
{
var oSon=window.document.getElementById("hint");
if (oSon==null) return;
with (oSon)
{
  innerText=guoguo.value;
  style.display="block";
  style.pixelLeft=window.event.clientX+window.document.body.scrollLeft+6;
  style.pixelTop=window.event.clientY+window.document.body.scrollTop+9;
}
}
function hidme()
{
var oSon=window.document.getElementById("hint");
if (oSon==null) return;
oSon.style.display="none";
}
//-->
</SCRIPT>
<BODY>
<text id=guoguo value=ga>
<a href=# onmouseover=showme() onmouseout=hidme() onmousemove=showme() son=hint>dfdfd</a>
<div id=hint style="display:none"></div>
</BODY>
</HTML>
---------------------------------------------------------------------------------------------------------

------------

57.弹出窗口
方法一:<body onload="openwen()"> 浏览器读页面时弹出窗口;
方法二:<body onunload="openwen()"> 浏览器离开页面时弹出窗口;
方法三:用一个连接调用:<a href="#" onclick="openwin()">打开一个窗口</a>
注意:使用的"#"是虚连接。
方法四:用一个按钮调用:<input type="button" onclick="openwin()" value="打开窗口"> 何时装载script


58.动态改变字体的大小
function doZoom(size)
{
   document.getElementById('zoom').style.fontSize=size+'px'
}

function aa()
{
   var newWin=window.open(url);
   newWin.document.form1.text1.value=value1;
}改变弹出窗口上域的属性
opener.document.form2.text2.value=value2;改变父窗口的域的值

59.判断是何种浏览器
var name = navigator.appName;
if (name == "Microsoft Internet Explorer")
alert("IE");
else if (name == "Netscape")
alert("NS");//

60.vbsscript确定框
<script language="VBScript">
<!--
MsgBox "确定删除吗?", 4
//-->
</script>//

61.复制内容到剪切板
function JM_cc(bb)
{
    var ob=eval("document.form1."+bb);
    ob.select();
    js=ob.createTextRange();
    js.execCommand("Copy");
}//

62.java中建立数据库连接取数据
public void init()
{
String url="jdbc:odbc:javadata";
try
{
  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  Connection con=DriverManager.getConnection(url,"sa","");//mssql database user SA and password
  DatabaseMetaData dma=con.getMetaData();
  System.out.println("Connect to"+dma.getURL());
  System.out.println(";Driver "+dma.getDriverName());
  System.out.println(";Version "+dma.getDriverVersion());
  System.out.println("");
  Statement stmt=con.createStatement();
  ResultSet rs=stmt.executeQuery("select * from company.dbo.TB_NAME where number=1");//Sql
  rs.next();
  String dispresult=rs.getString("name");
  System.out.println(dispresult);// Instead,you can display it in Paint() or use AWT etc.
  rs.close();
  stmt.close();
  con.close();
}
catch(SQLException ex)
{
  System.out.println("!!!SQL Exception !!!");
  while(ex!=null)
  {
   System.out.println("SQLState:"+ex.getSQLState());
   System.out.println("Message:"+ex.getMessage());
   System.out.println("Vendor:"+ex.getErrorCode());
   ex=ex.getNextException();
   System.out.println("");
  }

}
catch(java.lang.Exception ex)
{
  ex.printStackTrace();
}
}//


63.最小化窗口
window.blur()//


64.文档的路径
document.URL//

65.定时执行某段程序
setTimeout("change_color()",600);

66.设置为主页
function makeHome(){
  netscape.security.PrivilegeManager.enablePrivilege("UniversalPreferencesWrite");
  navigator.preference("browser.startup.homepage", location.href);
}//

67.设置为收藏
function addFav(){
  if(ie)
    window.external.AddFavorite(location.href,'WWW.OGRISH.COM : GROTESQUE MOVIES AND PICTURES');
  if(ns)
    alert("Thanks for the bookmark!\n\nNetscape users click OK then press CTRL-D");
}//

68.判断cookie是否可用
navigator.cookieEnabled;//

69.显示有模式的有页面的弹出窗口
function setbgcolor_onclick()
{
var color = showModalDialog("/mailpage/compose/colorsel.html",0,"help=0");
if (color != null)
{
  document.compose.bgcolor.value = color;
}
}//


70.截取小数点后两位
var a=3454545.4454545;
alert(a.toFixed(2));//


71.禁止选择页面上的文字来拷贝
<script>
function noEffect() {
  with (event) {
    returnValue = false;
    cancelBubble = true;
  }
  return;
}
</script>
<body onselectstart="noEffect()" oncontextmenu="noEffect()">//

72.屏蔽右键菜单
oncontextmenu="event.returnValue = false"//

73.事件禁止起泡
event.cancelBubble = true//

74.禁止在输入框打开输入法
<input style="ime-mode: disabled">//

75.屏蔽汉字和空格
<input name="txt"><input type="submit" onClick="alert(!/[^ -}]|\s/.test(txt.value))">//

76.用javascript判断文件是否存在
function Exists(filespec)
{
if (filespec)
{
  var fso;
  fso = new ActiveXObject("Scripting.FileSystemObject");
  alert(fso.FileExists(filespec));
}
}
选择图片 <input type=file name=f1><p>
<input type="submit" onClick="Exists(f1.value)">//

77.获得当前的文本框选中的文字
<input onmouseup="alert(document.selection.createRange().text)" value=123>//

78.跳转至目标页面,同时不可返回
<a href="javascript:location.replace('http://www.sohu.com/')">sohu.com</a>//


79.获得当前的行是表格的第几行
<script>
function getrow(obj)
{
   if(event.srcElement.tagName=="TD"){
   curRow=event.srcElement.parentElement;
   alert("这是第"+(curRow.rowIndex+1)+"行");

   }
}
</script>

<table border="1" width="100%" onclick=getrow(this)>
  <tr>
    <td width="20%"> </td>
    <td width="20%"> </td>
    <td width="20%"> </td>
    <td width="20%"> </td>
    <td width="20%"> </td>
  </tr>
  <tr>
    <td width="20%"> </td>
    <td width="20%"> </td>
    <td width="20%"> </td>
    <td width="20%"> </td>
    <td width="20%"> </td>
  </tr>
</table>//

80.删除表格某行,xx表示某行,下标从0开始计算
document.all.myTable.deleteRow(xx)//

81.动态的向表格中添加行
<table id="t1" border="1">
</table>
<script language="JavaScript">
function add()
{
   t1.insertRow().insertCell().innerHTML = '<input name="test'+t1.rows.length+'">';
}//



82.event.x,event.clientX,event.offsetX区别:
x:设置或者是得到鼠标相对于目标事件的父元素的外边界在x坐标上的位置。 clientX:相对于客户区域的x坐标位置,不

包括滚动条,就是正文区域。 offsetx:设置或者是得到鼠标相对于目标事件的父元素的内边界在x坐标上的位置。
screenX:相对于用户屏幕。


83.显示是鼠标按钮的哪个
<body onMouseDown="alert(event.button)">点Mouse看看//

84.打开C盘
<form action="file:///c|/"><input type="submit" value="c:\ drive"></form>//

85.当前屏幕的分辨率
screen.width、screen.height//

86.设置表格中的内容
tbl.rows[0].cells[1].innerText=document.form.text1.value;//

上一篇:常用JavaScript代码5 下一篇:常用JavaScript代码7

评论总数:0 [ 查看全部 ] 网友评论


关于我们隐私版权广告服务友情链接联系我们网站地图