如何在此javascript代码(imagepicker)中获取其他值?

时间:2015-02-10 13:08:05

标签: javascript jquery

我想让用户选择合适的图片,将用户转发到其他页面。当用户选择两个图像时出现问题。当用户选择这两个图片时,我不知道如何设置转发,任何想法? Here's 我使用%windir%\Temp文件夹的工具。谢谢你们的帮助!

 <html>
<head>
      <!-- scripts for imagepicker -->
    <link rel="stylesheet" href="assets/css/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="assets/js/image-picker.js"></script>
    <script type="text/javascript">


        "use strict";
        //wait for the page to be fully loaded
        window.onload = function() {
            initialize();
        }
    </script>
    <title></title>
</head>
<body>
    <div class="container">
        <br> <br> <br> <br>
        <div class="jumbotron">

                    <!-- 2 obrazki -->

                    <div class="row">
          <div class="col-xs-6 col-md-3"></div>
          <center>
          <select multiple="multiple" class="image-picker show-html" id="selectImg">

          <div class="col-xs-6 col-md-3 flags container" >
            <option class="col-xs-6 col-md-3 flags" data-img-src="assets/media/img/german.png" value="1"></option>
          </div>

          <div class="col-xs-6 col-md-3 flags container" >
            <option class="col-xs-6 col-md-3 flags" data-img-src="assets/media/img/spain.png" value="2"></option>
          </div>

        </div>
        </select>
       </center> 
            <!-- 2 obrazki -->
              </div>
              <div class="form-group container">
                <center>
                    <p>Kliknij tu i <br><a id="forwardButton" class="btn btn-lg btn-success" type="submit" href="#" role="button">Dołącz do Poliglotów</a></p>
                </center>
              </div>
            </form>
        </div>
    </div>


    <!--SCRIPTS imgpickr DON'T TOUCH-->

  <script>

    $("select").imagepicker();
    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 == 1){
              window.location = "https://www.google.com";
            }
            else if(choice == 2){
              window.location = "https://www.facebook.com";

            }
            else if(choice == 1 && choice == 2){
              window.location = "https://www.twitter.com";

            }

        } 
    }


  </script>




</body>
</html>

1 个答案:

答案 0 :(得分:0)