javascript 单元格互换值

<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>Test</title>
    <script type="text/javascript" src="<%=request.getContextPath() 
	%>/jquery-js/jquery-1.3.2.js"></script>
    <script type="text/javascript">
    	$(function(){
    		//jQuery 实现
    		var juser;
    		var jpsw;
    		$('#toChange').click(function(){
    			$('input[type="text"]').each(function(){
    				juser = $(this).val();
    			});
    			$('input[type="password"]').each(function(){
    				jpsw = $(this).val();
    			});
    			$('#userId').val(jpsw);
    			$('#pswId').val(juser);
    		});
    	});
    	function toChange()
    	{
    		var vuser;
    		var vpsw;
    		var obj = document.getElementsByTagName('input');
    		//var obj =document.frm.elements;
    		for(var i=0;i<obj.length;i++){
			//	alert(obj[i].name+" "+obj[i].type);
				if(obj[i].type=='text'){
					vuser = obj[i].value ;
				}else if(obj[i].type=='password'){
					vpsw = obj[i].value ;
				}
	   		}
	   		document.getElementById('userId').value = vpsw;
	   		document.getElementById('pswId').value = vuser;    	}
    </script>
    
  </head>
  <body>
     <td><input type="text" name="user" id="userId"></td>
     <td><input type="password" name="psw" id="pswId"></td>
     <input type="button" value="js实现" onclick="toChange()">
     <input type="button" value="jQuery实现" id="toChange">
  </body>
</html>

如果把id="userId"、id="pswId"去掉,而且在火狐浏览器下面不支持
document.getElementById('NAME'),怎么实现?
如果把name值得name="user"、name="psw"也去掉呢?
document.getElementsByName()、document.getElementById,docment.getElementsTagName区别
[
var obj = document.getElementsByName('user');
            alert('obj = '+obj[0].value);
]

你可能感兴趣的:(JavaScript,java,html,jquery)