JS如何传参的问题

1. 页面:这里需要注意radio不能写id,如果写了id的属性后就不能正常显示raido,所以没办法就只能在js中用this.value来获取div1。这个div1、div2、div3实际上是3个对话框的id属性值。只能想办法这样来获取它的id了。

<input name="quest20"  type="radio" value="div1" disabled onclick="javascript:openDivDiag(this);"/>

<input name="quest20"  type="radio" value="div2" disabled onclick="javascript:openDivDiag(this);"/>

<input name="quest19"  type="radio" value="div3" disabled onclick="javascript:openDivDiag(this);"/>

 

2. js部分:
function openDivDiag(param){
	document.getElementById(param.value).style.display = "inline";
}

 

3. 各个div:
<div id="div1" onmousedown="m(this.id)" style="display:none;left: 0px;top: 0px; position: absolute; left: 150px; top: 2500px;">
	<table width="50%" border="0" cellpadding="3" cellspacing="1" 
	style="background: #ff7300; 
	position:static;filter:progid:DXImageTransform.Microsoft.DropShadow
	(color=#666666,offX=4,offY=4,positives=true)" align="center">
	<tr style="cursor: move;">
		<td><font color="#FFFFFF">AAAAAAAAAA:</font></td>
		<td align="right"><input name="div1" type="button" value="x" 
	onClick="javascript:closeDivDiag(this);" style="cursor:pointer;"></td>
	</tr>
	<tr>
		<td colspan="2" width="100%" bgcolor="#FFFFFF" height="150" 
	align="middle">中国asp之家<br /><br />网址:<a href="http://www.aspxhome.com">http://www.aspxhome.com</a></td>
	</tr>
	</table>
</div>

<div id="div2" onmousedown="m(this.id)" style="display:none;left: 0px;top: 0px; position: absolute; left: 150px; top: 2500px;">
	<table width="50%" border="0" cellpadding="3" cellspacing="1" 
	style="background: #ff7300; 
	position:static;filter:progid:DXImageTransform.Microsoft.DropShadow
	(color=#666666,offX=4,offY=4,positives=true)" align="center">
	<tr style="cursor: move;">
		<td><font color="#FFFFFF">BBBBBBBBBB:</font></td>
		<td align="right"><input name="div2" type="button" value="x" 
	onClick="javascript:closeDivDiag(this);" style="cursor:pointer;"></td>
	</tr>
	<tr>
		<td colspan="2" width="100%" bgcolor="#FFFFFF" height="150" 
	align="middle">中国asp之家<br /><br />网址:<a href="http://www.aspxhome.com">http://www.aspxhome.com</a></td>
	</tr>
	</table>
</div>

<div id="div3" onmousedown="m(this.id)" style="display:none;left: 0px;top: 0px; position: absolute; left: 150px; top: 2500px;">
	<table width="50%" border="0" cellpadding="3" cellspacing="1" 
	style="background: #ff7300; 
	position:static;filter:progid:DXImageTransform.Microsoft.DropShadow
	(color=#666666,offX=4,offY=4,positives=true)" align="center">
	<tr style="cursor: move;">
		<td><font color="#FFFFFF">CCCCCCCC:</font></td>
		<td align="right"><input name="div3" type="button" value="x" 
	onClick="javascript:closeDivDiag(this);" style="cursor:pointer;"></td>
	</tr>
	<tr>
		<td colspan="2" width="100%" bgcolor="#FFFFFF" height="150" 
	align="middle">中国asp之家<br /><br />网址:<a href="http://www.aspxhome.com">http://www.aspxhome.com</a></td>
	</tr>
	</table>
</div>

 

4. 在各个div里面有关闭的按钮代码的解释:这里也不知道为什么也不能写id的属性值,所以想办法就只能写name的属性值了,在js中同样通过this.name来获取div1、div2、div3这3个id值。
<input name="div1" type="button" value="x" 
	onClick="javascript:closeDivDiag(this);" style="cursor:pointer;">

<input name="div2" type="button" value="x" 
	onClick="javascript:closeDivDiag(this);" style="cursor:pointer;">

<input name="div3" type="button" value="x" 
	onClick="javascript:closeDivDiag(this);" style="cursor:pointer;">

 

5. js关闭部分代码:
function closeDivDiag(param){
	document.getElementById(param.name).style.display = "none";
}

 

 

二、传递参数二(简体版)

1.js部分:
onClick = clearquiz('1');
onClick = clearquiz('2');
onClick = clearquiz('3');
2.传递参数写法:直接写参数名就可以了,不用写var temp
function clearquiz(temp) {
 	alert(temp);
}

 

你可能感兴趣的:(JavaScript,Microsoft,asp)