我正在构建一个多选择问卷,使用jQuery在悬停时切换单选按钮。我有一个跨度的每一个可能的答案,在里面,我有一个单选按钮,我想交换源在悬停。
这是我拍的照片,不是单选按钮。我有两个图像,选中和未选中,当用户悬停时,我正在交换src。
因此,当用户悬停在单选按钮上或单选按钮旁边的实际文本时,按钮会显示一个点。
这是我的span,它包含单选按钮和文本(请记住,我有其中的5个)。
<span class='choice' id='A'><img src="images/radioUnchecked.png" width="20" height="21" class='radioButton'>A) Naked woman</span>那么,当用户悬停在文本上时,我如何使用jQuery来锁定单选按钮呢?
编辑:这是用于切换的jQuery i,但是只有当用户在图像上徘徊时才能工作。
$('img.radioButton').hover(function () {
this.src = 'images/radioChecked.png';
}, function () {
this.src = 'images/radioUnchecked.png';
});发布于 2012-05-30 17:56:17
$('span.choice').hover(function() {
$('img.radioButton', this).attr('src', 'images/radioChecked.png')
}, function() {
$('img.radioButton', this).attr('src', 'images/radioUnchecked.png')
});如果choice类有更多的元素,那么可以尝试如下:
$('span.choice').has('img.radioButton').hover(function() {
$('img.radioButton', this).attr('src', 'images/radioChecked.png')
}, function() {
$('img.radioButton', this).attr('src', 'images/radioUnchecked.png')
});$('span.choice').has('img.radioButton')将只检测包含img.radioButton的span。
https://stackoverflow.com/questions/10821634
复制相似问题