繁体   English   中英

Internet Explorer无法使用基于php生成的select选项值的JavaScript函数

[英]Internet Explorer doesn't work with JavaScript function based on php generated select option values

我有一个基于php生成的select选项值的JavaScript函数的Internet Explorer问题。 我搜索了一下,我认为问题与那些相似

在IE中设置选择框的innerHtml

Internet Explorer在chain select上未显示<option>值

我基于这些解决方案尝试了其他尝试,但没有成功。 我的应用程序是这样的:

  • 我的HTML文件中有一个嵌套选择:

     <div id="selectCountry" class="infobox_map"> <p align="center"><b>Selection relating to Country:</b></p> <div id="country-navigation"> <select id="first-choice" size="1" style="width: 234px" onclick="zoomToCountry(value); fillCountryInfo(value)"> <option selected value="base">Choose a Country</option> <option value="Bolivia">Bolivia</option> <option value="India">India</option> <option value="Switzerland">Switzerland</option> <option value="Tanzania">United Republic of Tanzania</option> </select> </div> <div id="project_navigation"> <select id="second-choice" size="1" style="width: 234px" onclick="zoomToProject(value)"> <option selected value="base">Select a project</option> <option>Projects</option> </select> </div> </div> 

关联的JavaScript函数如下所示:

        $(function() {

        $("#first-choice").change(function() {
            $("#factbook").load("factbook.php?choice=" + $("#first-choice").val());
            $("#second-choice").load("select_country.php?choice=" + $("#first-choice").val());
        });

        $("#first-choice-proj").change(function() {
            $("#second-choice-proj").load("select_project.php?choice_proj=" + $("#first-choice-proj").val());
        });         
    });

所以我有两个选择。 完成第一个选择(国家/地区)后,我正在使用Php连接到数据库并生成第二个选择(项目)。 这可以正常工作,但是另一个JavaScript函数(“ zoomToProject()”)使用生成的值

<select id="second-choice" size="1" style="width: 234px" onclick="zoomToProject(value)">

不起作用! 该应用程序可在Firefox,Chrome和IE 9中正常运行,但IE 8失败,因为该函数未获取所需的参数“值”。

是否有人对此有建议或想法?

干杯,D。Stroeer

好的,谢谢您的快速回复! 我正在使用jquery-1.3.2。 这是“ zoomToProject()”函数的代码:

function zoomToProject(value) {
xval = wfs_climate.getFeaturesByAttribute('name', value);
yval = wfs_climate.getFeaturesByAttribute('name', value);   
xcoord = xval[0].geometry.x;
ycoord = yval[0].geometry.y;        
map.setCenter(new OpenLayers.LonLat(xcoord,ycoord), 10);

}

我知道您想使用load函数,但是将ajax与json一起使用对我来说是很动态的,如下所示:

index.html:

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Populating select box with ajax data</title>
    <script
      src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js">
    </script>
    <script>
      $(function()
      {
        $.get('get_country_codes.php', function(codes)
        {
          var select = $('#country_codes');

          for (var i = 0; i < codes.length; i++)
          {
            var code = codes[i];
            var option = $('<option/>');

            option.val(code.id);
            option.text(code.text);

            select.append(option);
          }
        }, 'json');
      });
    </script>
  </head>
  <body>
    <select id="country_codes"></select>  
  </body>
</html>

get_country_codes.php:

<?
    $arr = array();

    $obj = new StdClass();
    $obj->id = 213;
    $obj->text = "Algeria";
    $arr[] = $obj;

    $obj = new StdClass();
    $obj->id = 46;
    $obj->text = "Sweden";
    $arr[] = $obj;

    echo json_encode($arr);
?>

这样的解决方案可能会解决您的问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM