我有这个功能的问题,我使用这个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>
答案 0 :(得分:0)
我认为你还没有初始化图像选择器。
来自http://rvera.github.io/image-picker/
然后只需在目标元素上调用imagepicker。 $( “选择”)。imagepicker()
为什么要在缩小版本中加载image-picker.js和相同的文件?