javascript - 为什么imagepicker程序js中的这个功能不起作用?

标签 javascript debugging

我对这个功能有问题,我用这个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/

Then just call imagepicker on the target elements. $("select").imagepicker()

为什么要加载 image-picker.js 和压缩版本中的相同文件?

关于javascript - 为什么imagepicker程序js中的这个功能不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28236113/

相关文章:

java - 在 Debug模式下运行程序非常慢

javascript - 如何统计文本节点中实际显示在网页上的字符数?

javascript - Meteor 在服务器上调用 Accounts.verifyEmail?

javascript - 使用多对多关联向 SailsJS 模型添加重复项

javascript - 输入复选框在选中时更改 div 颜色

java - Phonegap 调试远程用户

c# - 如何在 Debug模式下浏览所有 session 变量?

powershell - 在 PowerShell 中检查是否处于 Debug模式

java - 如何在android或Java中使用调试器?

javascript - 绑定(bind)多个事件时调用特定函数