通过getjson查询json包中的数据,然后将包中的数据填写到table里

  1. 键入框input    submit键提交,结果执行function

  2. getjson读取json包中的数据

  3. while do 对键入框的信息与json的信息比对,比对成功后将json包中的数据填写到table中的对应位置。

思路是这样,求大神告诉怎么能将键入信息和json的对象名进行比较,怎么填表

demo.html:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>demo</title>
</head>

<body>
    <div>    
        <input type="text" name="txtCount"/>
        <input type="submit" name = "Submit" value="Go!" onclick="function()"/>
    </div>

    <div id="myForm">
        <table>
            <thead>
                <tr>
                    <th>类目</th>
                    <th>数据</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>1</td>
                    <td></td>
                </tr>
                <tr>
                    <td>2</td>
                    <td></td>
                </tr>
                <tr>
                    <td>3</td>
                    <td></td>
                </tr>
                <tr>
                    <td>4</td>
                    <td></td>
                </tr>
                <tr>
                    <td>5</td>
                    <td></td>
                </tr>
                <tr>
                    <td>6</td>
                    <td></td>
                </tr>
                <tr>
                    <td>7</td>
                    <td></td>
                </tr>
                <tr>
                    <td>8</td>
                    <td></td>
                </tr>
                <tr>
                    <td>9</td>
                    <td></td>
                </tr>
                <tr>
                    <td>10</td>
                    <td></td>
                </tr>                                
            </tbody>
        </table>
    </div>
    
     <script type="text/javascript">
        function SreachBlock(){
            $.getJSON('BlockDataObject.json').done(function (data) {    
                var    h = document.myForm.txtCount.value;
                while(h == "json包中的对象名"){
                    //输出表格内该对象对应的对象数据
            });
        }
    </script>
</body>
</html>

BlockDataObject.json:

[
    1: {
        "1": "lala",
        "2": "a",
        "3": "b",
        "4": "c",
        "5": "d",
        "6": "e",
        "7": "f",
        "8": "g",
        "9": "h",
        "10": "i"
    },
    2: {
        "1": "nana",
        "2": "q",
        "3": "w",
        "4": "e",
        "5": "r",
        "6": "t",
        "7": "y",
        "8": "u",
        "9": "i",
        "10": "o"
    },
    3: {
        "1": "kaka",
        "2": "z",
        "3": "x",
        "4": "c",
        "5": "v",
        "6": "b",
        "7": "n",
        "8": "m",
        "9": "l",
        "10": "k"
    }
]


qq_伽利略扭秤_0
浏览 1789回答 1
1回答

橋本奈奈未

obj.hasOwnProperty(prop) 方法会返回一个布尔值,指示对象是否具有指定的属性作为自身(不继承)属性。
打开App,查看更多内容
随时随地看视频慕课网APP