0

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

[定価]タブをクリックして、オプションの1つを[追加]します。これにより、下の選択ボックスの値が設定されますが、変更されません。イベントは正しく発生していますが、選択したアイテムは変更されていません。

これはデータ型の問題でしょうか?

$('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 に答える