Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在特定范围内定位图像?_Javascript_Jquery_Html_Css - Fatal编程技术网

Javascript 如何在特定范围内定位图像?

Javascript 如何在特定范围内定位图像?,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我正在构建一个多选问卷,使用jQuery在悬停状态下切换单选按钮。对于每个可能的答案,我都有一个跨度,里面有一个单选按钮,我想在悬停时交换源代码 现在这些是我制作的图像,不是实际的单选按钮。我有两个图像,选中和未选中,当用户悬停时,我交换src 因此,当用户将鼠标悬停在单选按钮本身或单选按钮旁边的实际文本上时,按钮会显示一个点 这是我的跨度,包含单选按钮和文本(请记住,我有5个) 如果类选项中有更多元素,则可以尝试以下操作: $('span.choice').has('img.radioButt

我正在构建一个多选问卷,使用jQuery在悬停状态下切换单选按钮。对于每个可能的答案,我都有一个跨度,里面有一个单选按钮,我想在悬停时交换源代码

现在这些是我制作的图像,不是实际的单选按钮。我有两个图像,选中和未选中,当用户悬停时,我交换src

因此,当用户将鼠标悬停在单选按钮本身或单选按钮旁边的实际文本上时,按钮会显示一个点

这是我的跨度,包含单选按钮和文本(请记住,我有5个)

如果类
选项中有更多元素,则可以尝试以下操作:

$('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')
});