我大约有10张图片,当 :hover
每张图片都有一个ajax.load
那将是触发器。我要做 10 jquery.hover
,但有件事告诉我有更好的解决方案。
我在想类似的事情
case 1 : load a
case 2 : load b
case 3 : load c
etc...
如何在 jquery 中执行此操作?
明白10张不同的图片加上10种不同的文字必须加载在<div>
中所以现在我正在做
$('#a).hover.load('file' #tx-a');
$('#b).hover.load('file' #tx-b');
$('#c).hover.load('file' #tx-c');
最佳答案
这是一个简单的例子:
<p id="status"> </p>
<img class="viewable" id="unique" src="foo.jpg"/><br/>
<img class="viewable" id="id" src="foo.jpg"/><br/>
<img class="viewable" id="for" src="foo.jpg"/><br/>
<img class="viewable" id="each" src="foo.jpg"/><br/>
<img class="viewable" id="element" src="foo.jpg"/><br/>
<script type="text/javascript">
$(function() {
var stuff = ['hello', 'world', 'you', 'look', 'nice'];
$('.viewable').hover(
// triggered when mouse moves onto element
function() {
var index = $('.viewable').index(this);
// Replace this next line with a jQuery AJAX call. Pass the index
// as a parameter to whatever location you are pulling the text
// from, and have the AJAX callback stuff the text into the
// #status element. This is just a placeholder.
$('#status').html('Hover IN, index ' + index + ' (' + stuff[index] + ')');
},
// triggered when mouse move off of element
function() {
// Optional: clear status element when mouse moves off image
$('#status').html(' ');
}
);
});
</script>
关于jquery - 在 jQuery 中是否有使用 if 或 case 的替代方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/718158/