javascript对变量通过数组获取

老虎说测试 前端技术字数 1422阅读4分44秒阅读模式
摘要今天在处理质量信息系统问题的时候,发现了一个问题,就是通过javascript用数组的方式获取其中的值的时候,在IE下会存在不能获取到的情况,其他的浏览器测试都是正常的,先看看情况...

今天在处理质量信息系统问题的时候,发现了一个问题,就是通过javascript用数组的方式获取其中的值的时候,在IE下会存在不能获取到的情况,其他的浏览器测试都是正常的,先看看情况:

1、文章源自陈学虎-https://chenxuehu.com/article/2013/09/1353.html

[php]文章源自陈学虎-https://chenxuehu.com/article/2013/09/1353.html

<script type="text/javascript">
$().ready(function(){
$('#report_name0').hide();
$('#report_name1').hide();文章源自陈学虎-https://chenxuehu.com/article/2013/09/1353.html

<?php if (isset($flagPidCount)){
if ($projs[$flagPidCount]['description'] == '内销')$flag="0";
else $flag="1";
echo "$('#report_name$flag').show();";
}else{?>
$('#report_name<?php if ($projs[0]['description'] == '内销')echo "0";else echo "1";?>').show();
<?php }?>
$("select[name = 'proj_id']").change(function(){
var s="";
s=$("select[name='proj_id']").find('option:selected').val();
alert(s);
if(s[0] == '内'){//专业的获取在IE7中是无效的
$('#report_name0').show();
$('#report_name1').hide();
}else{
$('#report_name0').hide();
$('#report_name1').show();
}
});
});
</script>文章源自陈学虎-https://chenxuehu.com/article/2013/09/1353.html

[/php]文章源自陈学虎-https://chenxuehu.com/article/2013/09/1353.html

javascript对变量通过数组获取文章源自陈学虎-https://chenxuehu.com/article/2013/09/1353.html

所以我们的更改策略为,必须改为数组形式,将变量直接转为数组,然后通过数组获取因此,就有了下面的代码:文章源自陈学虎-https://chenxuehu.com/article/2013/09/1353.html

[php]文章源自陈学虎-https://chenxuehu.com/article/2013/09/1353.html

<script type="text/javascript">
$().ready(function(){
$('#report_name0').hide();
$('#report_name1').hide();文章源自陈学虎-https://chenxuehu.com/article/2013/09/1353.html

<?php if (isset($flagPidCount)){
if ($projs[$flagPidCount]['description'] == '内销')$flag="0";
else $flag="1";
echo "$('#report_name$flag').show();";
}else{?>
$('#report_name<?php if ($projs[0]['description'] == '内销')echo "0";else echo "1";?>').show();
<?php }?>
$("select[name = 'proj_id']").change(function(){
var s="";
s=$("select[name='proj_id']").find('option:selected').val();
var array = s.split(',');
if(array[0] == '内销'){
$('#report_name0').show();
$('#report_name1').hide();
}else{
$('#report_name0').hide();
$('#report_name1').show();
}
});
});
</script>文章源自陈学虎-https://chenxuehu.com/article/2013/09/1353.html

[/php]

经过测试这样可以完美解决!

 
  • 版权声明:本文为原创文章,转载请附上原文出处链接及本声明。
  • 转载请注明:javascript对变量通过数组获取 | https://chenxuehu.com/article/2013/09/1353.html