1

这段代码在 FF 中运行良好,而不是在 IE 中。

var target = $("#targetSelectBox")
var vals   = values.split(";");
for (var i = 0; i < vals.length; i++) {
        var parts = vals[i].split(":");
 target.append($('<option />').val(parts[0].trim()).text(parts[1].trim()));
}
4

1 回答 1

2

您在第一行之后缺少一个分号:

var target = $("#targetSelectBox")//;

确保此选择器确实在找到您的元素:

<select id="targetSelectBox">
  <!-- options to come -->
</select>

我们还需要查看您的代码的完整部分,包括values开始的内容。此外,请确保正确引用了 jQuery,您甚至可以考虑target在 jQuery 包装器中包装您的内部引用:

var newOption = $("<option>").val( parts[0] ).text( parts[1] );
$(target).append(newOption);

在线功能示例:http: //jsbin.com/ibeci/edit

于 2010-01-21T19:43:26.910 回答