开发者

jquery mobile - assigning different data-heme to options while adding them to select list?

assigning different data-heme to options while appending to select list?

    // in a for loop - adding options to a select list...
    if (tempstatus == 'DONE')
    { selectlistVar
    .append($('<option>', { value : results.rows.item(x).item_num })
    .text(tempListDisplayVar));
    }
    else
    { selectlistVar
    .append($('<option>', { value : results.rows.item(x).item_num })
    .text(tempListDisplayVar));
    }

so far i've tried things - like:

    .append($('<option data-theme="d">', { value : results.rows.item(x).item_num }) 

&

    $('<option value='+myVar+' data-theme="d">'+tempList开发者_如何学JAVADisplayVar+'</option>').appendTo(selectlistVar);

none seem to allow me to assign a data-theme. Any suggestions?


you could try using the jquery data() function. It won't be stored in your markup, but hidden in the element.

var opt = $('<option>', {value: 'val', text: 'text'}).data('theme', 'themeValue');
opt.data('theme'); //returns 'themeValue'

If you just need the data-theme attribute added, you should try to add it after building the element (for some reason is not working during building the creation of the element)

var opt = $('<option>', {value: 'val', text: 'text'});
opt.attr('data-theme', 'themeValue');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜