为什么我的javascript在我的弹出窗口模式中不起作用

时间:2017-05-02 00:40:40

标签: javascript c# jquery ajax asp.net-mvc

我有一个视图,其中我有一个弹出模式,它获取一个搜索字符串并搜索数据库中的详细信息。

问题是,当我编写搜索字符串并按搜索按钮时,不会触发javascript。

以下是我的代码

<html>
<head>
    <script src="~/Scripts/jquery-1.11.1.min.js"></script>
    <script src="~/Scripts/jquery-ui-1.8.11.js"></script>

    <script>
        $(document).ready(function () {
            $("#records_table").on("click", "tr", function () {

                $(this).addClass('selected').siblings().removeClass('selected');
                var usern = $(this).find('td:nth-child(1)').html();
                var name = $(this).find('td:nth-child(2)').html();
                var email = $(this).find('td:nth-child(3)').html();
                var emails = $(this).find('td:nth-child(4)').html();
                document.getElementById("1").value = usern;
                document.getElementById("2").value = name;
                document.getElementById("3").value = email;
                document.getElementById("4").value = emails;
            });

        $('#openBtn').click(function (event) {
            $(".rower").empty();
            var search = $('#searchAttr').val();          

            if (search != '') {
                $.getJSON('@Url.Content("~/DBTestAccPAcs/GetRecord")', { search: search }, function (FacilityData) {
                    $(function () {                        
                        for (var i = 0; i < FacilityData.DivID.length; i = i+4) {
                            $('<tr class="rower">').append(
                                    $('<td>').text(FacilityData.DivID[i]),
                                    $('<td>').text(FacilityData.DivID[i + 1]),
                                    $('<td>').text(FacilityData.DivID[i + 2]),
                                    $('<td>').text(FacilityData.DivID[i + 3])
                                ).appendTo('#records_table');
                        }
                    });
                });
            }
        });
        });            
    </script>
    <style>
        /* Full-width input fields */
input[type=text], input[type=password] {
    width: 100%;
    padding: 12px 20px;
    margin: 8px 0;
    display: inline-block;
    border: 1px solid #ccc;
    box-sizing: border-box;
}

/* Set a style for all buttons */
button {
    background-color: #4CAF50;
    color: white;
    padding: 14px 20px;
    margin: 8px 0;
    border: none;
    cursor: pointer;
    width: 100%;
}

/* Extra styles for the cancel button */
.cancelbtn {
    padding: 14px 20px;
    background-color: #f44336;
}

/* Float cancel and signup buttons and add an equal width */
.cancelbtn,.signupbtn {
    float: left;
    width: 50%;
}

/* Add padding to container elements */
.container {
    padding: 16px;
}

/* The Modal (background) */
.modal {
    display: none; /* Hidden by default */
    position: fixed; /* Stay in place */
    z-index: 1; /* Sit on top */
    left: 0;
    top: 0;
    width: 100%; /* Full width */
    height: 100%; /* Full height */
    overflow: auto; /* Enable scroll if needed */
    background-color: rgb(0,0,0); /* Fallback color */
    background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
    padding-top: 60px;
}

/* Modal Content/Box */
.modal-content {
    background-color: #fefefe;
    margin: 5% auto 15% auto; /* 5% from the top, 15% from the bottom and centered */
    border: 1px solid #888;
    width: 80%; /* Could be more or less, depending on screen size */
}

/* The Close Button (x) */
.close {
    position: absolute;
    right: 35px;
    top: 15px;
    color: #000;
    font-size: 40px;
    font-weight: bold;
}

.close:hover,
.close:focus {
    color: red;
    cursor: pointer;
}

/* Clear floats */
.clearfix::after {
    content: "";
    clear: both;
    display: table;
}

    </style>
</head>
<body>
    <input id="searchAttr" name="searchAttr" />
    <button onclick="document.getElementById('id01').style.display='block'">Sign Up</button>
    <input type="text" id="1" /><input type="text" id="2" /><input type="text" id="3" /><input type="text" id="4" />




    <!-- Button to open the modal -->


    <!-- The Modal (contains the Sign Up form) -->
    <div id="id01" class="modal">
        <span onclick="document.getElementById('id01').style.display='none'" class="close" title="Close Modal">&times;</span>
        @*<form class="modal-content animate" action="/action_page.php">*@
        <div class="modal-content animate">
            <div class="container">
                <div class="my">
                    <input id="searchAttr" name="searchAttr" />
                    <button href="#myModal" id="openBtn" data-toggle="modal" class="btn btn-success">search</button>
                </div>
                <div id="result">
                    <div class="table-responsive" style="height:300px; overflow:auto;">
                        <table id="records_table" border='1' class="table table-bordered table-condensed table-hover table-responsive">
                            <thead>
                                <tr>
                                    <th>Vendor Part Number</th>
                                    <th>Description</th>
                                    <th>Location Code</th>
                                    <th>Quantity</th>
                                </tr>
                            </thead>
                            <tbody id="getrid"></tbody>

                        </table>
                    </div>
                </div>
                <div class="clearfix">
                    <button type="button" onclick="document.getElementById('id01').style.display='none'" class="cancelbtn">Cancel</button>

                </div>
            </div>
        </div>
    </div>   
</body>
</html>

真的很感激任何帮助。

由于

0 个答案:

没有答案