未捕获的TypeError:无法读取属性' prop'使用Bootstrap Multiselect时未定义

时间:2018-03-26 06:16:57

标签: php jquery html twitter-bootstrap-3 bootstrap-multiselect

我正在使用David Stutz的Bootstrap Multiselect。当我没有在我的JS中初始化多选时,它会显示一个带有所有选项的div,没有错误。但是当我使用multiselect方法时,它会给出

  

未捕获的TypeError:无法读取' prop' ...

的属性

我已经检查了所有包含的脚本和CSS文件。我也跟着提出了一些问题。最流行的解决方案是检查我是否包含两次相同的JS文件。但我不是。

我还试过包含多个版本的jquery并更改了<script src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.19.4/moment.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/0.9.15/js/bootstrap-multiselect.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/js/bootstrap-datetimepicker.min.js"></script> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/0.9.15/css/bootstrap-multiselect.css"> <link rel="stylesheet" href="https://cdn.rawgit.com/Eonasdan/bootstrap-datetimepicker/e8bddc60e73c1ec2475f827be36e1957af72e2ea/build/css/bootstrap-datetimepicker.css"> 的CDN,但这也没有用。

这是脚本列表

<div class="col-lg-2">
    <select name="tags" class="form-control que-tags multiselect" multiple="multiple">
        <option value="select">Select</option>
    </select>
</div>

此外,选择列表是通过PHP生成的,然后我使用jquery将选项列表附加到select标记中。

以下是代码段

HTML:

if(isset($_POST['contextid']) && !empty($_POST['contextid'])) {

    $sel_tags = "SELECT DISTINCT tagid FROM mdl_tag_instance WHERE contextid=".$_POST['contextid'];
    $get_tags = mysqli_query($con, $sel_tags);
    $tag_num = mysqli_num_rows($get_tags);

    if($tag_num>0) {
        while($row_tag = mysqli_fetch_assoc($get_tags)) {
            $tags[] = $row_tag['tagid'];
        }
        $all_tag_ids = join("','",$tags);

        $sel_tag_names = "SELECT * FROM mdl_tag WHERE id IN ('".$all_tag_ids."')";
        $get_tag_names = mysqli_query($con, $sel_tag_names);
        $num_tagnames = mysqli_num_rows($get_tag_names);

        if($num_tagnames>0){
            while($row_tagnames = mysqli_fetch_assoc($get_tag_names)){
                echo "<option value=".$row_tagnames['id'].">".$row_tagnames['rawname']."</option>";
            }
        }
    }
    // echo $all_tag_ids;
    else {
        echo "<option value=\"invalid\">Invalid Option</option>";
    }
}

PHP:

$.ajax({
    type: "POST",
    url: "ajaxData.php",
    data: "contextid="+contextid,

    success: function(data) {
        $('.que-tags').html(data);
    },
    error: function(data) {
        alert(data.statusText);
    }
});

//Multiselect initialisation
$('.multiselect').multiselect();

JS:

TemplateBinding

0 个答案:

没有答案