1

I have a select menu and I dynamically insert some values from a database:

 markup += '<option value=' + option["value"] + '>' + option["alias"] + '</option>';

some values, however, contain double quotes. to try and get around this I tried:

markup += '<option value=' + JSON.stringify(option["value"]) + '>' + option["alias"] + '</option>';

For examples sake lets assume the value is 6"Rocket (this is actually my problem child) When I try and read the value using Jquery .val() I always get 6.

What to do SO?

4

1 に答える 1

3

この問題を回避する最も簡単な方法は、HTMLの文字列を挿入するのではなく、DOMを削除することです。

var sel = $('#some_dropdown');
...
$('<option />', {value: option.value, text: option.alias}).appendTo(sel);
于 2012-08-14T14:34:05.077 に答える