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

js的startWith和endWith
<html>
	<head>
		<script>
		function doStartAll() {
			var allCheck = document.updateBusinessForm.getElementsByTagName("input");
			var checkList='';
			for(var i=0; i<allCheck.length; i++){
				var tagBody = allCheck[i];
					if(tagBody.getAttribute("name").startWith('name1')){
						checkList += tagBody.value  + '|';
					}
			}
			alert(checkList);
		}	
		
		String.prototype.startWith=function(str){
			if(str==null||str==""||this.length==0||str.length>this.length)
			  return false;
			if(this.substr(0,str.length)==str)
			  return true;
			else
			  return false;
			return true;
		}
		String.prototype.endWith=function(str){
			if(str==null||str==""||this.length==0||str.length>this.length)
			  return false;
			if(this.substring(this.length-str.length)==str)
			  return true;
			else
			  return false;
			return true;
		}

		</script>
	</head>
<body>
<form name="updateBusinessForm" method="get" action="businessUpdateStateEpaper.do">
	<input name="name1.a" value="a"/>
	<input name="name1.b" value="b"/>
	<input name="name1.c" value="c"/>
	<input name="name1.d" value="d"/>

	<input type="submit" class="button" id="" value="启用" onClick="doStartAll();"/>
</form>
</body>
</html>

?