浏览 779 次
|
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
|---|---|
| 作者 | 正文 |
|
最后更新时间:2007-11-21 关键字: JS AJAX 控制multiple型select元素 上下移动
写JS脚本最烦心之处莫过于由于浏览器标准不统一导致的程序复杂性,现在,尽管已经有很多AJAX框架对各种浏览器的区分都做了封装,但现实中一些小问题的处理上,考虑使用这些东西似乎不太现实。这几天,刚好需要做一个小小的demo页面其中有些东西刚好可以写出来以备后用。 需求如下: 1.现有一select框,代码如下: xml 代码
2.有两个按钮,通过这两个按钮的点击事件来控制select框中内容的上下移动。 xml 代码
开始时,也没有太多留意只是从网上找找源码三两改,用IE打开进行测试,似乎没有什么问题,调试代码如下: xml 代码
由于客户的特殊需求,不管IE是否能够执行,但必须保证Firefox可以执行。在这种变态的要求下,我不得不把我的页面拉到Firefox上调试一次。最终的结果让我大失所望——全乱了,仔细研究了一下问题所在才发现是Firefox不支持add方法,怎么办,得改用其他的方式来实现了,想来想去也只有replace方法或许可以拿来用一下。怀着一种惴惴不安的尝试的心情,我将上面的代码进行了一些改动,具体改动后的内容如下: js 代码
代码完成后,调试在Firefox上没问题,但是当我拿到IE上进行测试时,什么都乱了,乱的一团糟。M$居然没有实现该W3C标准。反正也无所谓了,再写一个浏览器判断的方法问题解决。
声明:JavaEye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
|
|
| 返回顶楼 | |
|
最后更新时间:2007-11-21
服了.....
|
|
| 返回顶楼 | |
|
最后更新时间:2007-11-21
不要不懂乱说,明明就是你胡乱使用js,这样
<select name="hasitem" id="qqq" multiple size=19>
<option>t-mo bile game restrictions</option>
<option selected> aaa </option>
<option>gdsfgdsfgdsg</option>
<option>q2432342rewe432</option>
<option>2dfaesr34</option>
<option>t- mobile game restrictions</option>
<option>436t43ret4343</option>
<option>t-mob ile game restrictions</option>
<option>545435353453</option>
<option>t-mobile g ame restrictions</option>
<option>fdsgdggtrgreg</option>
<option>t-mob ile game restrictions</option>
<option>5756432534543</option>
<option>t-mobi e game restrictions</option>
<option>ggfy456454343</option>
<option>t-mob ile game restrictions</option>
</select>
<input name="buttong_04" type="button" value="up" class="button2" onClick="moveup();"><br>
<input name="buttong_05" type="button" value="down" class="button2" onClick="movedown();">
<script>
function moveup(){
var select_body =document.getElementById("qqq");
if(select_body.selectedIndex != -1){
var flag = select_body.selectedIndex;
if(flag==0){
alert("The Rule has already at the top level!");
return;
}
//这里加入判断是因为ie下面无法使用insertBefore来调换1号和0号元素,故使用这种方法
if(select_body.selectedIndex==1&&document.all)
{
var temp=select_body[select_body.selectedIndex];
var t=temp.parentNode;
temp.parentNode.removeChild(temp);
setTimeout(function(){
t.insertBefore(temp,t.options[0]);
},0)}
else
select_body[select_body.selectedIndex].parentNode.insertBefore(select_body[select_body.selectedIndex],select_body[select_body.selectedIndex-1])
}else
alert("Please select a Rule!");
}
function movedown(){
var select_body =document.getElementById("qqq");
if(select_body.selectedIndex != -1){
var flag = select_body.options.length;
if(select_body.selectedIndex==flag-1){
alert("Already reached bottom!");
return;
}
select_body[select_body.selectedIndex].parentNode.insertBefore(select_body.options[select_body.selectedIndex],select_body.options[select_body.selectedIndex+2])
}else
alert("Please select a Rule!");
}
</script>
|
|
| 返回顶楼 | |
|
最后更新时间:2007-11-22
这样好像没办法支持多选和跳选吧
|
|
| 返回顶楼 | |





