单击按钮,实现两个id值互换。
<html>
<head>
<script type="text/javascript">
function subOnClick(){
var text1=document.getElementById("txt1").value;
var text2=document.getElementById("txt2").value;
document.getElementById("txt1").value=text2;
document.getElementById("txt2").value=text1;
}
window.onload=function(){
document.getElementById("submitBtn1").onclick=subOnClick;
document.getElementById("submitBtn2").onclick=subOnClick;
}
</script>
</head>
<body>
<input type="text" value="123456" id="txt1" />
<input type="submit" id="submitBtn1"/>
<input type="text" value="123" id="txt2" />
<input type="submit" id="submitBtn2" />
</body>
</html>