为什么图像选择器程序中的这个函数 js 不起作用

Why this function in imagepicker program js doesn't work?

本文关键字:函数 js 不起作用 图像 选择器 程序 为什么      更新时间:2023-09-26

我对这个功能有问题,我使用此 http://rvera.github.io/image-picker/,我想为用户创建选项,以便在选择合适的图像后转发到正确的网站。转发工作正常,但图像使用此代码消失。有什么想法吗?

<!DOCTYPE HTML>
<html>
<head>
<link rel="stylesheet" href="css.css">
<script src="js.js"></script>

<!-- scripts for imagepicker -->
    <link rel="stylesheet" href="image-picker.css">
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <script type="text/javascript" src="image-picker.js"></script>
    <script type="text/javascript" src="image-picker.min.js"></script>
    <script type="text/javascript">
        "use strict";
        //wait for the page to be fully loaded
        window.onload = function() {
            initialize();
        }
    </script>

</head>
<body>

<!--code for imagepicker-->
<select multiple="multiple" class="image-picker show-html" id="selectImg">
  <option data-img-src="http://placekitten.com/220/200" value="http://cats.com">Cute Kitten 1</option>
  <option data-img-src="http://placekitten.com/180/200" value="http://dogs.com">Cute Kitten 2</option>
  <option data-img-src="http://placekitten.com/130/200" value="http://dogsandcats.com">Cute Kitten 3</option>
</select>
<button href="#" id="forwardButton">Forward</button>
<script>
function initialize() {
    var choice = document.getElementById("selectImg").value;
    //changes destination when you set or change your choice
    document.getElementById("selectImg").onchange = function() {
        choice = document.getElementById("selectImg").value;
    }
    //when button is clicked
    document.getElementById("forwardButton").onclick = function() {
        if (choice !== ("" || "undefined")) {
            window.location = choice;
        }       
    }
}
</script>
</body>
</html>

我认为您尚未初始化图像选择器。

从 http://rvera.github.io/image-picker/

然后只需在目标元素上调用图像选择器。 $("select").imagepicker()

为什么要在缩小版本中加载图像选择器.js和相同的文件?