0

http://medfor.petersenuploads.co.uk/product.php/698/2/clear-ps-honey-jar-with-metal-screw-cap

单击“全价”选项卡并“添加”选项之一。这应该设置下面选择框的值,但它不会改变。该事件正确触发但未更改所选项目。

这可能是数据类型问题吗?

$('a.addspecific').live(
    'click', function(e) {
        e.preventDefault();
        //console.log($(this).data('sterility'));
        console.log("IN");
        //Update dropdowns for JShop functionality
        $('#capacity').find("option").filter(function() {
            return $(this).text() == $(this).data('capacity');  
        }).attr('selected',true);
        console.log($(this).data('capacity'));
        $('#sterility').find("option").filter(function() {
            return $(this).text() == $(this).data('sterility');  
        }).attr('selected',true);
        console.log($(this).data('sterility'));
        $('#labeltype').find("option").filter(function() {
            return $(this).text() == $(this).data('labeltype');  
        }).attr('selected',true);
        console.log($(this).data('labeltype'));
        $('#itemspercase').find("option").filter(function() {
            return $(this).text() == $(this).data('itemspercase');  
        }).attr('selected',true);
        console.log($(this).data('itemspercase'));
        console.log("OUT");


    }
4

2 回答 2

4

这个上下文是失败的,试试吧:

console.log("IN");
var thes = this;

$('#capacity').find("option").filter(function() {
     return $(this).text() == $(thes).data('capacity');  
}).attr('selected',true);
于 2012-10-19T16:39:58.410 回答
0

代替

.attr('selected',true);

尝试使用

.prop('selected',true);
于 2012-10-19T16:14:20.510 回答