English 中文(简体)
Java打字清单箱除非在表IE8中发挥作用
原标题:Javascript sorting listbox works unless in a table IE8

我的一项职能是,当用户选择一个或多个项目时,将这些项目移至清单箱顶(选定的提炼)和滚动到顶,以便其重新可见。 它在我测试的所有主要浏览器工作。 当我拥有这一职能时,问题就出现在一个桌子内。 当我这样做并使用国际电子数据8时,它就进行分类和复制;适当强调,但只是向顶点倾斜。 Java本通过基本的JALint检查,网页通过超文本验证。 我是否找到了IE8的qui子? 我把这个名单箱式和样子放在一起;滚动功能错失了吗?

<script type="text/javascript">
function Arrange(obj) {
    var countSel = 0, countNSel = 0, i, arr_selected = [], arr_unselected = [];
    for (i = 0; i <= obj.length - 1; i++) {
        if (obj.options[i].selected) {
            //create array with all selected items then sort it
            arr_selected[countSel] = [];
            arr_selected[countSel][0] = obj.options[i].text;
            arr_selected[countSel][1] = obj.options[i].value;
            countSel = countSel + 1;
            arr_selected.sort();
        }
        else {
            //create array with all UNselected items then sort it
            arr_unselected[countNSel] = [];
            arr_unselected[countNSel][0] = obj.options[i].text;
            arr_unselected[countNSel][1] = obj.options[i].value;
            countNSel = countNSel + 1;
            arr_unselected.sort();
        }
    }
    if (countSel !== 0) {
        //overwrite listbox options with selected items
        for (i = 0; i <= countSel - 1; i++) {
            obj.options[i] = new Option(arr_selected[i][0], arr_selected[i][1]);
        }
        //overwrite listbox options with UNselected items
        for (i = 0; i <= countNSel - 1; i++) {
            obj.options[countSel] = new Option(arr_unselected[i][0], arr_unselected[i][1]);
            countSel = countSel + 1;
        }
    }

    //for showing selected items
    //scroll to the top of the list and select the appropriate items
    //it s in reverse order because IE8 wanted to only scroll to the last item selected
    obj.selectedIndex = 0;
    for (i = arr_selected.length - 1; i >= 0; i--) {
        obj.options[i].selected = true;
    }
}
</script>
</head>
<body>
<form name="frm" action="post">
<table><tr><td>test:</td><td>
<select size="4" name="cbostaffcontact" multiple onblur="Arrange(document.forms[0].cbostaffcontact);">
<option value="user1">Al</option>
<option value="user2">Bob</option>
<option value="user3">Christy</option>
<option value="user4">Jane</option>
<option value="user5">Randy</option>
<option value="user6">Tom</option>
<option value="user7">Zed</option>
</select>
</td></tr></table>
</form>
最佳回答

这很可能是国际能源论坛8中的一个rk子,但你的法典实际上并没有说什么是roll,因此,我要指责国际能源8。 http://jsfiddle.net/Df7dQ/“rel=“nofollow noreferer” 解决你的问题:

obj.scrollTop=0;
问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签