<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="js/jquery.1.11.min.js" ></script>
<script>
$(document).ready(function(){
$(".chooseImg").on("click", function(){
$(this).prev().prop('checked', true);
});
});
</script>
</head>
<body>
<div>
<p><input type="radio" name="a"><img src="images/backimage1.jpg" class="chooseImg" width=100 height=30 ></p>
<p><input type="radio" name="a"><img src="images/backimage1.jpg" class="chooseImg" width=100 height=30 ></p>
<p><input type="radio" name="a"><img src="images/backimage1.jpg" class="chooseImg" width=100 height=30 ></p>
<p><input type="radio" name="a"><img src="images/backimage1.jpg" class="chooseImg" width=100 height=30 ></p>
</div>
</body>
</html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="js/jquery.1.11.min.js" ></script>
<script>
$(document).ready(function(){
$(".chooseImg").on("click", function(){
$(this).prev().prop('checked', true);
});
});
</script>
</head>
<body>
<div>
<p><input type="radio" name="a"><img src="images/backimage1.jpg" class="chooseImg" width=100 height=30 ></p>
<p><input type="radio" name="a"><img src="images/backimage1.jpg" class="chooseImg" width=100 height=30 ></p>
<p><input type="radio" name="a"><img src="images/backimage1.jpg" class="chooseImg" width=100 height=30 ></p>
<p><input type="radio" name="a"><img src="images/backimage1.jpg" class="chooseImg" width=100 height=30 ></p>
</div>
</body>
</html>
在以上代码中 attr()方法是不可以使用的,因为attr()不可以返回布尔型的属性而prop()可以。还一种情况是只添加属性名不需要写属性值的就可以生效的也同样使用.prop()方法。比如:checked、disable