下载首页下载分类最近更新排 行 榜国产软件国外软件汉化补丁本站论坛BT下载页
  • 设为首页
  • 收藏本站
  • 联系我们
您的位置:首页网页制作JS/Ajax → js技巧收集(200多个)
js技巧收集(200多个)
出处:本站整理 作者:佚名 日期:2007-5-7 17:09:38 人气: [ ]


146.定义一个将日期类型转化为字符串的方法
function guoguo_date()
{
 var tmp1,tmp2;
 tmp1 =this.getMonth()+1+"";
 if(tmp1.length<2)
  tmp1="0"+tmp1;
 tmp2 =this.getDate()+"";
 if(tmp2.length<2)
  tmp2="0"+tmp2;
 
 return this.getYear()+"-"+tmp1+"-"+tmp2;
}
Date.prototype.toLiteString=guoguo_date;
alert(new Date().toLiteString())

 

147. pasta 是有四个参数的构造器,定义对象。
function pasta(grain, width, shape, hasEgg)
{
    // 是用什么粮食做的?
    this.grain = grain;

    // 多宽?(数值)
    this.width = width;    

    // 横截面形状?(字符串)
    this.shape = shape;  

    // 是否加蛋黄?(boolean)
    this.hasEgg = hasEgg; 

    //定义方法
    this.toString=aa;
}
function aa()
{
 ;
}
//定义了对象构造器后,用 new 运算符创建对象实例。
var spaghetti = new pasta("wheat", 0.2, "circle", true);
var linguine = new pasta("wheat", 0.3, "oval", true);
//补充定义属性,spaghetti和linguine都将自动获得新的属性
pasta.prototype.foodgroup = "carbohydrates";


148.打印出错误原因
try
{
 x = y   // 产生错误。
}
catch(e)
{
   document.write(e.description)   //打印 "'y' is undefined".
}//

149.生成Excel文件并保存
var ExcelSheet;
ExcelApp = new ActiveXObject("Excel.Application");
ExcelSheet = new ActiveXObject("Excel.Sheet");
//本代码启动创建对象的应用程序(在这种情况下,Microsoft Excel 工作表)。一旦对象被创建,就可以用定义的对

象变量在代码中引用它。 在下面的例子中,通过对象变量 ExcelSheet 访问新对象的属性和方法和其他 Excel 对象,

包括 Application 对象和 ActiveSheet.Cells 集合。
// 使 Excel 通过 Application 对象可见。
ExcelSheet.Application.Visible = true;
// 将一些文本放置到表格的第一格中。
ExcelSheet.ActiveSheet.Cells(1,1).Value = "This is column A, row 1";
// 保存表格。
ExcelSheet.SaveAs("C:\\TEST.XLS");
// 用 Application 对象用 Quit 方法关闭 Excel。
ExcelSheet.Application.Quit();//

150.根据标签获得一组对象
var coll = document.all.tags("DIV");
if (coll!=null)
{
for (i=0; i<coll.length; i++)
...
}//
   
151.实现打印预览及打印
<OBJECT classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height=0 id=wb name=wb width=0></OBJECT>
<input type=button value=打印预览 onclick="wb.execwb(7,1)">
<input type=button onClick=document.all.wb.ExecWB(6,1) value="打印">//

152.不通过form,直接通过名字引用对象
<INPUT TYPE="text" NAME="gg" value=aaaaa>
<SCRIPT LANGUAGE="JavaScript">
<!--
alert(document.all.gg.value)
//-->
</SCRIPT>//

153.使鼠标滚轮失效
function document.onmousewheel()
{
 return false;
}//
 
154.创建弹出窗口
<SCRIPT LANGUAGE="JScript">
  var oPopup = window.createPopup();
  var oPopupBody = oPopup.document.body;
  oPopupBody.innerHTML = "Display some <B>HTML</B> here.";
  oPopup.show(100, 100, 200, 50, document.body);
</SCRIPT>//

相关文章
相关软件
评论人 评论内容摘要(共 0 条,查看完整内容) 得分 0 发表时间
关于本站 | 广告服务 | 版权声明 | 联系我们 | | 联系我 | 交流群:1361692 7710545
本站部分带宽由:华夏名网武汉IDC数据中心 赞助[排名不分先后] Powered By 零度软件园
本站软件均来源于网络,仅供学习所用。若侵犯了你的权益,请立即通知我们,我们将第一时间删除!