日期:2014-05-16  浏览次数:20432 次

js函数积累一
一.取得当前行tr元素
function getTR() {
    var obj=event.srcElement;
    while (obj.tagName !="TR") {
        obj = obj.parentElement;
    }
    return obj;
}


二.判断当前字符串a是否是以字符串b为结尾:
function endWidth(s1,s2){
		if(s1.length < s2.length){
			return false;
		}

		if(s1 == s2){
			return false;
		}

		if(s1.substring(s1.length-s2.length) == s2){
			return true;
		}

return false;
}

三.根据不同的tableid添加不同内容的一行:
function addParameterRow(tableid){
	var parameterObj = document.getElementById(tableid);
	var newTr = parameterObj.insertRow();

	var newTd0 = newTr.insertCell();
	var newTd1 = newTr.insertCell();
	var newTd2 = newTr.insertCell();

	if (tableid == "addons_kenerlParameters") {
		newTd0.innerHTML = '<input name="kenerlParamGroup" type="text" size="20" maxlength="32"/>';
		newTd1.innerHTML = '<input name="kenerlParamName" type="text" size="20" maxlength="32"/>:<input name="kenerlParamValue" type="text" size="20" maxlength="32"/>';
		newTd2.innerHTML = '<input name=btnAddKenerlParam type=button class=button value=添加 onclick=addParameterRow("addons_kenerlParameters") style=cursor:hand/> <input name=delAddKenerlParam type=button class=button value=删除 onclick=delRow("addons_kenerlParameters") style=cursor:hand/>';
	}
	else if (tableid == "addons_hardwareTypeParameters") {
		newTd0.innerHTML = '机房:<input name="dataCenter" type="text" size="15" maxlength="20" />';
		newTd1.innerHTML = '硬件类型:<input name="serviceType" type="text" size="15" maxlength="10" />';
		newTd2.innerHTML = '<input name=btnAddHardwareTypeParam type=button class=button value="添加" onclick=addParameterRow("addons_hardwareTypeParameters") style=cursor:hand/> <input name=delAddHardwareTypeParam type=button class=button value=删除 onclick=delRow("addons_hardwareTypeParameters") style=cursor:hand/>';
	}
	else {
		newTd0.innerHTML = '<input name="functionParamGroup" type="text" size="20" maxlength="32"/>';
		newTd1.innerHTML = '<input name="functionParamName" type="text" size="20" maxlength="32"/>:<input name="functionParamValue" type="text" size="20" maxlength="32"/>';
		newTd2.innerHTML = '<input name=btnAddFunctionParam type=button class=button value=添加 onclick=addParameterRow("addons_functionParameters") style=cursor:hand/> <input name=delAddFunctionParam type=button class=button value=删除 onclick=delRow("addons_functionParameters") style=cursor:hand/>';
	}


	newTd0.align = "center";
	newTd1.align = "center";
	newTd2.align = "center";

}