<选择>只显示选定选项的第一个字符 [英] <select> only shows first char of selected option

查看:80
本文介绍了<选择>只显示选定选项的第一个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个标准的选择框,我使用jquery通过附加选项来填充,但由于某些原因,IE9仅显示所选选项的第一个字符。毋庸置疑,它在FireFox和Chrome中运行良好,但我必须支持IE9。我尝试了IE9兼容模式,但它没有区别,也没有设计选择或选项。



有没有人看过这个问题。是什么造成的?您是如何解决这个问题的?





简化的代码示例:

 < select id = selectCCYValueColumn =ccyIDDisplayColumn =ccySymbol>< / select> 


$ b $ .each(res.result,function(key,value){
$('#selectCCY')。append('< option value ='+ value [$('#selectCCY')。attr('ValueColumn')] +'>'value [$('#selectCCY')。attr('DisplayColumn')] +'<选项>');
});

res.result是一个简单的json数组,如下所示:

  [{ccyID:1,ccySymbol:GBP},{ccyID:2,ccySymbol:AUD},{ccyID :3,ccySymbol:USD}] 

OH BUGGER !!!它在我简化的例子中工作正常,所以问题在其他地方。抱歉。原始代码是漫长而复杂的粘贴在这里,但会让我知道当我找到答案。



过了一段时间....



好的,我将问题归结为$(selector).each()循环内的ajax调用。循环遍历所有选择框并异步填充选项。如果我使它成为同步调用,选择框具有正确的宽度并正确显示,但如果它是异步调用,则选择框仅显示图像中的第一个字符。仍然在这方面工作,将再次回到你身边。



我仍然想知道什么会导致选择框显示不正确。我可以做出解决方法并使其正确显示,但这并不能回答问题。这只是一个选择与它的选择,它应该总是工作,对吧?

在周末忽略问题....



对,我找到了解决方法。在进行ajax调用来填充选择框之前,我首先将css显示属性设置为'none',然后填充它,最后在ajax调用和填充完成时,只删除css显示'none'属性。



所以我仍然不知道为什么IE不喜欢我,但至少有一个解决方案。

解决方案

这是一个IE浏览器唯一的问题。首先将选择框上的CSS显示属性设置为'none',然后通过ajax调用填充它,最后当ajax调用完成并且填充选择框时,在选择框中删除css显示'none'属性


I have a standard select box which I'm populating using jquery by appending options, but for some reason IE9 only shows the first character of the selected option. Needless to say it works perfectly in FireFox and Chrome, but I have to support IE9. I tried the IE9 compatibility modes, but it made no difference, nor does styling the select or option.

Has anyone seen this issue before. What caused it? How did you fix it?

Simplified code sample:

<select id="selectCCY" ValueColumn="ccyID" DisplayColumn="ccySymbol" ></select>



$.each(res.result, function (key, value) {  
    $('#selectCCY').append('<option value="' + value[$('#selectCCY').attr('ValueColumn')]+ '">' + value[$('#selectCCY').attr('DisplayColumn')] + '</option>');
});

res.result is a simple json array like this:

[{"ccyID":1,"ccySymbol":"GBP"},{"ccyID":2,"ccySymbol":"AUD"},{"ccyID":3,"ccySymbol":"USD"}]

OH BUGGER!!! it works fine in my simplified example, so the problem is somewhere else. Sorry. The original code is to long and complex to paste here, but will let you know when I find the answer.

some time later....

OK, I got the problem down to an ajax call inside a $(selector).each() loop. The loop goes through all select boxes and asyncronously populates the options. If I make it a syncronous call, the select boxes have the correct width and show correctly, but if its an async call the select boxes only show the first char as in the image. still working on this, will get back to you again.

I still want to know what would cause a select box to display incorrectly. I can do workarounds and get it to show correctly, but that doesn't answer the question. It's just a select with options in it, it should always just work, right?

after a weekend of ignoring the issue ....

Right I found a workaround. Before doing the ajax call to populate the select box I first set the css display property to 'none' on it, then populate it and finally when the ajax call and population is complete I just remove the css display 'none' property.

So I still don't know why IE doesn't like me, but we have a solution at least.

解决方案

It is an IE only problem. First set the css display property on the select box to 'none', then populate it via your ajax call, finally when the ajax call is done and the select box is populated remove the css display 'none' property on the select box

这篇关于&LT;选择&GT;只显示选定选项的第一个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆