使用jQuery更改为点击图片的选项 [英] Change to a option on click image with jQuery
本文介绍了使用jQuery更改为点击图片的选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我单击某些图像,我想将选项更改为select.选项的值是参数的唯一ID.我想使用jQuery,但我是新手,我不知道怎么做.现在我有了这个:
I would like to change option into select if I click on some image. Value of option is a unique ID of parameter. I would like to use jQuery but I'm beginner and I don't know how. Now I have this:
$(document).ready(function () {
$('img').click(function(){
$("option:selected").removeAttr("selected");
$('option[value="' + $(this).attr("alt") + '"]').attr('selected', true);
});
});
但是它不起作用.所有资源都在这里 http://jsfiddle.net/EKaKw/2/.回答jsfiddle最好.谢谢.
But it doesn't work. All source are here http://jsfiddle.net/EKaKw/2/. Answer into jsfiddle would be best. Thanks advance.
推荐答案
首先,您没有选择jquery库,
the first, you havn't selected jquery library,
第二,有一种更简单的方法来更改jquery中的选择
the second, there is an easier way to change selection in jquery
$(document).ready(function () {
$('img').click(function(){
$('select').val($(this).attr('alt'));
});
});
小提琴: http://jsfiddle.net/73VmN/
这篇关于使用jQuery更改为点击图片的选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文