0

我有一个问题是 php 数据没有显示在选择框中。innerhtml 在 Internet Explorer 中不起作用。long_description_detail_list 数据未显示在选择框中。请帮助我

第一页:

<div id="long_description_detail_list" style="display:none;">
    <option value="0">Select..</option>
    <?php
    include_once('Model/Language.php');
    $r = new Language();
    $a = $r->Select();
    for($i = 0; $i < count($a); $i++)
    {
        print '<option value="'.$a[$i][0].'">'.$a[$i][1].'</option>';
    }
    ?>
</div>



<script language="javascript" type="text/javascript">

    //Browser Support Code
function create_long_description_detail_div(){
    if(count_table_long_description_detail() >=3) {
        alert("You can not add more than 3 long_description Details");
    }
    else {
        var ajaxRequest;  // The variable that makes Ajax possible!

        try{
            // Opera 8.0+, Firefox, Safari
            ajaxRequest = new XMLHttpRequest();
        } catch (e){
            // Internet Explorer Browsers
            try{
                ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try{
                    ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e){
                    // Something went wrong
                    alert("Your browser broke!");
                    return false;
                }
            }
        }
        // Create a function that will receive data sent from the server
        ajaxRequest.onreadystatechange = function(){
            if(ajaxRequest.readyState == 4){

                var blank_long_description_detail = ajaxRequest.responseText;
                document.getElementById('long_description_detail_counter').value ++;
                $('#my-all-long_description_details-here').append(blank_long_description_detail);
                set_new_height_of_step_2('inc');
                var long_description_list_counter = document.getElementById('long_description_detail_counter').value;
                var long_description_detail_list = document.getElementById('long_description_detail_list').innerHTML;
                document.getElementById('llanguage[' + long_description_list_counter + ']').innerHTML = long_description_detail_list;
            }
        }
        var long_description_detail_counter = document.getElementById('long_description_detail_counter').value;

        var queryString = "?long_description_detail_counter=" + long_description_detail_counter;
        ajaxRequest.open("GET", "Views/User/long_description/add_long_descriptions_detail.php" + queryString, true);
        ajaxRequest.send(null);
    }
}


</script>

数据未在名为 add_long_descriptions_detail.php 的第二页中显示:

<select id="llanguage[<?php echo $counter; ?>]" name="llanguage[<?php echo $counter; ?>]" class="txtBox">
                            <option value="0">Select..</option>

                            </select>
4

1 回答 1

0

IE 不支持用<select>with更新 a 的元素innerHTML,但您可以做的是使用 DOM,无论如何这始终是正确的处理方式。

让您的服务器端脚本返回一个 JSON 选项数组;它会让一切变得容易得多。

ajaxRequest.onreadystatechange = function() {
    if(ajaxRequest.readyState === 4) {
        // Parse the response
        var options = eval('(' + ajaxRequest.responseText + ')');

        // Get the box; I have no clue what this is
        var box = document.getElementById('llanguage[' + long_description_list_counter + ']');

        // Clear any current elements
        while(box.childNodes.length > 0) {
            box.removeChild(box.firstChild);
        }

        // Add new ones
        for(var i = 0; i < options.length; i++) {
            var newOption = document.createElement('option');
            newOption.value = options[i].value;
            newOption.appendChild(document.createTextNode(options[i].text));
        }
    }
};

(这与您的原始代码相比有所删减,但我相信您可以适应它。)

使用与旧 IE 兼容的 JSON 解析器而不是eval.

JSON 应如下所示:

[
    { "text": "Some text", "value": "some-value" }
]

您可以使用json_encodePHP 数组方便地生成它。

于 2013-09-08T20:24:46.747 回答