IE中元素的空值 [英] empty value of element in IE

查看:99
本文介绍了IE中元素的空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在firefox中的这段代码正在工作。

 < select id =ronnyname =ronnyonchange =AjaxPost() ;警报(的document.getElementById( '罗尼')的值);> 
< option id =selected_ronny>全部< / option>
<?php
foreach($ d_ronny as $ ronny)
{
if($ ronny == $ _POST ['ronny_select'])
{
echo< option selected id ='selected_ronny'> $ ronny< / option>;
}
else
{
echo< option> $ ronny< / option>;
}
}
?>
< / select>

这些选项是狐狸的例子:
All abc
123
xyz
当我选择 xyz 时,警报显示 xyz 。在IE浏览器中,这个提示是空的。



谢谢!

解决方案

对于onchange属性,您必须这样编码:

  onchange =AjaxPost(); alert(this.options [selectedIndex] 。值); 

如果您想使用id,请替换 thi document.getElementById('ronny')

 平变化= AjaxPost();警报(的document.getElementById( '罗尼')项[的selectedIndex]。价值。); 


This code in firefox is working. In IE the alert is empty.

<select id="ronny"  name="ronny" onchange="AjaxPost();alert(document.getElementById('ronny').value);">
   <option id="selected_ronny">All</option>
     <?php
      foreach($d_ronny as $ronny)
        {
          if ($ronny == $_POST['ronny_select'])
            {
              echo "<option selected id='selected_ronny'>$ronny</option>";
            }
          else
            {
              echo "<option>$ronny</option>";
            }
        }
     ?>
</select>

The options are fox example : All abc 123 xyz When i select xyz, the alert shows xyz. In IE the alert is empty.

thank you!

解决方案

For the onchange attribute you have to code like this :

onchange="AjaxPost();alert(this.options[selectedIndex].value);"

If you want to use the id, replace this by document.getElementById('ronny') :

onchange="AjaxPost();alert(document.getElementById('ronny').options[selectedIndex].value);"

这篇关于IE中元素的空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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