// temp Id generator
SEQUENCE = {
value : -1,
next : function() {
this.value = ++this.value;
return this.value;
};
//reset form element
function clearForm(formName) {
var formObj = document.forms[formName];
var formEl = formObj.elements;
for (var i=0; i<formEl.length; i++)
{
var element = formEl[i];
if (element.type == 'submit') { continue; }
if (element.type == 'reset') { continue; }
if (element.type == 'button') { continue; }
if (element.type == 'hidden') { continue; }
if (element.type == 'text') { element.value = ''; }
if (element.type == 'textarea') { element.value = ''; }
if (element.type == 'checkbox') { element.checked = false; }
if (element.type == 'radio') { element.checked = false; }
if (element.type == 'select-multiple') { element.selectedIndex = -1; }
if (element.type == 'select-one') { element.selectedIndex = -1; }
}
}
//define stringBuffer object in present project
function StringBuffer() {
this.__strings__ = new Array;
}
StringBuffer.prototype.append = function(str) {
this.__strings__.push(str);
return this;
};
StringBuffer.prototype.toString = function() {
return this.__strings__.join("");
};
//extend one method,'startWith' for original string object
if(!String.prototype.startWith){
String.prototype.startWith = function(param){
if(!param){
return false;
}else{
if(String(this).substring(0,String(param).length)==param){
return true;
}else{
return false;
}
}
};
}
/**
*
* @param divId one container
* @param info operation result message to show in the up DIV, such as: "Add Successfully!"
* @param isSuccess one sign whether operate successfully.Just two values:true or false.true means success.
* @returns undefined
*/
function showOperationResultInfo(divId,info,isSuccess){
$("#"+divId).removeAttr("style");
if(isSuccess){
$("#"+divId).attr("style","color:green");
}else{
$("#"+divId).attr("style","color:red");
}
$("#"+divId).empty();
$("#"+divId).html(info);
}
//refresh current page after ajax request
function deleteItemById(link){
$.ajax({
url :link,
cache:false,
context:document.body,
success:function(data){
if(!data.startWith("error")){
location.href="http://<%=request.getServerName()%>:<%=request.getServerPort()%><%=request.getContextPath() %>/demoWebSite/generateReport.action";
}else{
showOperationResultInfo("errorInfo",Messages.deleteFailureMess+",cause:"+data,false);
return false;
}
}
});
}
//obtain java version in the local PC by the plugin 'deployJava.js'
<script src="${contextPath}/js/plugins/deployJava.js"></script>
<script type="text/javascript">
var versions = deployJava.getJREs();
var reg = /1.6.|1.7.|1.8.|1.9./;
var result = reg.exec(versions);
if(null == result){
$("#appletUploadControl").innerHTML = "Your java version is: <b>" + versions + "</b>, please install java1.6 or upper version<br/>" + "You could download latest JDK from here:" + "<a href='http://www.oracle.com/technetwork/java/javase/downloads/index.html', target='_blank'>oracle-java</a>";
}
</script>
/*
DESC:extend one method,'Format' from original Date object
for example:
1. new Date().Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423 ;
2. new Date().Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18 ;
3. $("#createDateHtmlId").val(new Date().Format("MM/dd/yyyy")) .
*/
Date.prototype.Format = function(fmt) {
var o = {
"M+" : this.getMonth() + 1,
"d+" : this.getDate(),
"h+" : this.getHours(),
"m+" : this.getMinutes(),
"s+" : this.getSeconds(),
"q+" : Math.floor((this.getMonth() + 3) / 3),
"S" : this.getMilliseconds()
};
if (/(y+)/.test(fmt))
fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "")
.substr(4 - RegExp.$1.length));
for ( var k in o)
if (new RegExp("(" + k + ")").test(fmt))
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k])
: (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
};
<script type="text/javascript" src="${contextPath}/js/json.js"></script>
var project = {
value:"",
newProject:function(){
var one={
"id":"",
"project":"",
"projectCode":""
};
return one;
},
toJson:function(data){
return JSON.stringify(data);//the 'stringify' method from the plugin 'json.js'
},
};
//Construct one new instance
var item = project.newProject();
item.id=100;
item.project="demo";
item.projectCode="DE";
//Serialize object to character.After that,you can pass 'project.value' character as parameters for ajax request
project.value = project.toJson(item);
//transfer rgb to hexadecimal,such as (code section): var colorValue = rgb2hex($(this).parents("tr").css("color"));//"#ff6633"
function rgb2hex(rgb) {
if (!rgb) {
return '#FFFFFF'; //default color
}
var hex_rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
function hex(x) {return ("0" + parseInt(x).toString(16)).slice(-2);}
if (hex_rgb) {
return "#" + hex(hex_rgb[1]) + hex(hex_rgb[2]) + hex(hex_rgb[3]);
} else {
return rgb; //ie8 returns background-color in hex format then it will make compatible, you can improve it checking if format is in hexadecimal
}
}
//the use of ajax request to download file : <a href="javascript:void(0)" onclick="return downloadFile(URL.generateReportReq);"></a>
function downloadFile(link){
var flagObj=false;
$.ajax({
url :link,
context:document.body,
success:function(data){
if(!data.startWith("error")){
flagObj = true;
} else{
alert(Messages.downloadFileMess);
flagObj = false;
}
return;
}
});
return flagObj;
}
分享到:
相关推荐
JavaScript Tools Guide CC 开发说明
PHOTOSHOP javascript脚本开发的官方帮助文档,英文的。有需要的朋友可以下来看看,也可以当工具字典用。 2MB左右
JavaScript Tools Guide CS6.pdf
json解析js Tools json解析js Tools json解析js Tools json解析js Tools
可以将指定的html代码转的换为javascript代码,被多个页面引用。
Modern JavaScript Tools & Skills contains a collection of articles outlining essential tools and skills that every modern JavaScript developer should know. This book is for all front-end developers ...
NTVS supports the following: node projects Intellisense Debugging local & remote with support for Linux and MacOS Profiling node REPL with multi line editing Integrated npm GUI ...
JavaScript tools and marked with different colors!
Node.js Tools 1.2 (ntvs 1.2 for vs 2015)
Adobe CS3 套件相关的Java脚本编程指南。 全英文的哦... =。=! 目录 1 Introduction 2 The ExtendScript Toolkit ...9 Integrating XML into JavaScript 10 Scripting Access to XMP Metadata 11 Porting Guide
各种原生javascript工具函数,方便日常web开发
jquery.tools.js jquery.tools.js
jquery.tools.min.js 最新的1.2.7版本 jquery.min.js是压缩版的jquery库,是由完整版的jQuery库经过压缩得来,压缩后功能与未压缩的完全一样,只是将其中的空白字符、注释、空行等与逻辑无关的内容删除,并进行一些...
PS插件开发 illustrator插件开发 AE插件开发 ID插件开发 CEP插件开发
个人开发中总结和积累的js工具(JS tools that are summarized and accumulated in personal development) 文件名 说明 md5.js MD5加密算法 Base64.js Base64对称加密算法 timeage.js 将时间格式为相对时间,如 1小时...
JS工具 javascript工具
geotools汉语版资料
jquery.tools压缩版js,中带jquery1.4.2等多种js功能
解决maven项目找不到tools-1.8.0.jar的问题,缺失tools-1.8.0.jar包
jQuery Tools 是一套非常优秀的 Web UI 库,包括 Tab 容器,可折叠容器,工具提示,浮动层以及可滚动容器等等,可以为你的站点带来非同寻常的桌面般体验,这套工具的主要作用是显示内容,这是绝多多数站点最需要的...