Javascript 如何在特定范围内定位图像?
我正在构建一个多选问卷,使用jQuery在悬停状态下切换单选按钮。对于每个可能的答案,我都有一个跨度,里面有一个单选按钮,我想在悬停时交换源代码 现在这些是我制作的图像,不是实际的单选按钮。我有两个图像,选中和未选中,当用户悬停时,我交换src 因此,当用户将鼠标悬停在单选按钮本身或单选按钮旁边的实际文本上时,按钮会显示一个点 这是我的跨度,包含单选按钮和文本(请记住,我有5个) 如果类Javascript 如何在特定范围内定位图像?,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我正在构建一个多选问卷,使用jQuery在悬停状态下切换单选按钮。对于每个可能的答案,我都有一个跨度,里面有一个单选按钮,我想在悬停时交换源代码 现在这些是我制作的图像,不是实际的单选按钮。我有两个图像,选中和未选中,当用户悬停时,我交换src 因此,当用户将鼠标悬停在单选按钮本身或单选按钮旁边的实际文本上时,按钮会显示一个点 这是我的跨度,包含单选按钮和文本(请记住,我有5个) 如果类选项中有更多元素,则可以尝试以下操作: $('span.choice').has('img.radioButt
选项中有更多元素,则可以尝试以下操作:
$('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
如果类选项中有更多元素,则可以尝试以下操作:
$('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,我正在尝试$('span.choice')
,但它不起作用。那么跨度是必要的吗?为什么有时候你需要声明类的内容,有时候你不需要…我在尝试$('.choice')
,但它不起作用。那么跨度是必要的吗?为什么有时候你需要声明上课的内容,而有时候你不。。。
$('span.choice').hover(function() {
$('img.radioButton', this).attr('src', 'images/radioChecked.png')
}, function() {
$('img.radioButton', this).attr('src', 'images/radioUnchecked.png')
});
$('span.choice').has('img.radioButton').hover(function() {
$('img.radioButton', this).attr('src', 'images/radioChecked.png')
}, function() {
$('img.radioButton', this).attr('src', 'images/radioUnchecked.png')
});