2013-02-24 98 views
0

当有人点击我要的选择框选项更改为选项,通过它设置的值有一定的选择在我的网站的特定链接。变化选择框选择点击

我想我会通过添加某种的onClick的指向上的每个选择的价值做到这一点......但无法弄清楚使用的代码。

+0

过去的一些代码,并告诉我们你尝试过什么。 – sobol6803 2013-02-24 11:43:39

回答

2

在常规的JavaScript,你可以做类似的东西:

var selectBox = document.getElementById('selectBox'); 
var image = document.getElementbyId('someImage'); 

image.addEventListener('click', function() { 
    selectBox.selectedIndex = 1; // specify the selected index here. 
}); 

,你去选择框和图像的引用,并添加一个事件处理的图像设置选择框的选择指标。

如果您有jQuery的可用,你可以做类似:

$('img').click(function() { 
    $('select').val('new value'); // specify the new value 
}); 
+0

我有jQuery的可用,它实际上将是可点击图片或链接...继承人我的代码:

<选择名称= “productOptions [{$ option.option_id}]” ID = “选项_ {$ option.option_id}” 类= “的textBox {如果$ option.required} {需要/如果}”> <选项值= “13” >选项
{$product.name} Monster bigdaveygeorge 2013-02-24 12:35:48