猿问

新手问题,求解

1:testmodel,第71行,动态添加模块,我这样的写法太麻烦了,如果模块很大的话,求简洁方式

2:testmodel部分,第130行 div id=login模块 我想让其在顶层自动居中在界面最中央,但是就是居中不了。求正确方式

3:testcode部分,我用的单例,但是js写法很纳闷,不知道是不是写的正确

4:假设有两个js文档名字为A.js,B.js,A如何访问B内的东西?(不在HTML里把两个都给引入了,仅引入其中一个A)

testmode:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style>
			body{
				margin: 10px auto;
				width: 90%;
				height: auto;
				background-color: #A9A9A9;
			}
			img{
				width: 150px;
				height: 100px;
			}
			#cont{
				background-color: #A9A9A9;
				text-align: center;
				overflow: hidden;
				float: left;
				margin: 3px;
				position: relative;
			}
			#div1{
				border: 1px solid #FF0000;
				float: left;
				background-color: #FAEBD7;
			}
			#text{
				width: 70px;
				position: absolute;
				background-color: #FFA500;
				transform: rotate(-45deg) translate(-20px,-10px);
				-webkit-transform: rotate(-45deg) translate(-20px,-10px);
				font-size: 13px;
				padding: 3px 3px;
			}
			#zhezhao{
				background-color: #0000CC;
				width: 100%;
				height: 100%;
				position: absolute;
				opacity: 0;
				
			}
			#zhezhao:hover{
				opacity:0.5;
			}
			#login{
				background-color: #F0F8FF;
				position: absolute;
				padding: 20px 20px;
				margin-left: auto;
				margin-right: auto;
			}
			#closs{
				width: 20px;
				height: 20px;
				text-align: center;
				background-color: green;
				top: 0px;
				right: 0px;
				
			}
			
		</style>
		<script>
			window.onload=function(){
				var txtdiv=document.getElementById("text");
				txtdiv.stopPropagation;
				var ap=document.getElementById("append");
				for (var i=0;i<6;i++) {
					//这么添加模块,如果模块很大,就写法很麻烦,求简洁方式
					var alldiv=document.createElement("div");
					alldiv.setAttribute("id","cont");
					ap.appendChild(alldiv);
					
					var div1=document.createElement("div");
					div1.setAttribute("id","div1");
					alldiv.appendChild(div1); 
					
					var imgs=document.createElement("img");
					imgs.setAttribute("src","assets/5vip.jpg");
					imgs.setAttribute("width","150px");
					imgs.setAttribute("heigth","100px");
					div1.appendChild(imgs);
					
					var div2=document.createElement("div");
					div2.innerHTML="第二VIP";
					div1.appendChild(div2); 
					
					var zz=document.createElement("div");
					zz.setAttribute("id","zhezhao");
					alldiv.appendChild(zz);
					
				}
				//建立点击监听,但是这里却有故障,直接执行了。。。
				document.getElementById("closs").addEventListener("click",logins(0));
//				document.getElementById("denglu").addEventListener("click",logins(1));
			}
			function logins(num){
				console.log(num);
				if(num==0)document.getElementById("login").style.opacity=0;
				if(num==1)document.getElementById("login").style.opacity=1; 
			}
		</script>
	</head> 
	<body>
		<div><button id="denglu">登陆</button></div>
		<div id="append">
			<div id="cont">
				
				<div id="div1">
					<img src="assets/5vip.jpg" />
					<div>第一VIP</div>
				</div>
				<div id="zhezhao"></div>
				<div id="text">示例1</div>
				
			</div>
			<div id="cont">
				<div id="div1">
					<img src="assets/5vip.jpg"  />
					<div>第一VIP</div>
				</div>
				<div id="zhezhao"></div>
			</div>
		</div>	
		<div id="login">
			<div id="closs">X</div>
			帐号:<input type="text" />
			</br></br>
			密码:<input type="password" />
			</br></br>
			<button>提交测试</button>
		</div>
	</body>
</html>
---------------------------------------------------------------------------------------------
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

testcode部分:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="jquery-1.12.2.min.js"></script>
</head>
<body>
<script>
var result={
calliden:function(arg){
var _xw=iden(arg);
console.log(_xw)
return _xw;
} 
}
//document.write(result.calliden(["612324198205250038","555"]));
document.write(result.calliden("999"));
function iden (arg){
var msg;
var arrmsg;
if(arg.constructor==Array){
if(!arrmsg){
arrmsg=new Array;
}
arrmsg=[];
for (var i=0;i<arg.length;i++) {
//
arrmsg.push(new IdentityCodeValid(arg[i]))
}
return arrmsg;
}
if(arg.constructor==String){
if(!msg){
msg=new IdentityCodeValid(arg)
}
return msg;
}
msg=null;
arrmsg=[];
}
function IdentityCodeValid(code) {     
    return 1231231;
}
</script>
</body>
</html>


azureks
浏览 1498回答 1
1回答
随时随地看视频慕课网APP
我要回答