$(‘.test‘).get(0)
或
$(‘.test‘)[0]
例子:
<html>
<head>
<title>转换为DOM对象</title>
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
//alert($(‘#txtName‘).value);//打印undefined
alert($(‘.test‘).get(1).value);//alert($(‘.test‘)[1].value);
});
</script>
</head>
<body>
姓名:<input id="txtName" name="txtName" value="tomzhang" class="test" />
年龄:<input id="txtAge" name="txtAge" value="31" class="test" />
</body>
</html>
时间: 2024-10-06 10:40:06