首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >能够投票和安排投票

能够投票和安排投票
EN

Stack Overflow用户
提问于 2015-11-06 16:25:49
回答 1查看 32关注 0票数 0

所以这份名单有效了!现在轮到我的下一招了。我希望用户能够对那些列出的电影投票多少次,当他们投票的时候,我希望那些被投票的电影被列在“你是最好的电影”下面。到目前为止,我得到的是:

在HTML中:

代码语言:javascript
复制
<!DOCTYPE html>
<html>
<link rel="stylesheet" text="text/css" href="movies.css">
  <head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>

<title> 
Hello World 
    </title>
  </head>
  <body>
    <h1>My Favorite Movies</h1>
        <div id = "first">
            <input type="text" id="movie" placeholder="Movie">
            <button id="enter">Enter</button>
        </div>
    <div id="list"><u>Chosen Films:</u></div>
    <!-- <div>Chosen Films: <span id="list"></span></div> -->
    <!-- <div id="films"></div> -->
    <div id="best">You're Best Films:</div>



<script type="text/javascript" src="movies.js"></script>
  </body>
</html>

在我的js中:

代码语言:javascript
复制
/ The function that creates the first list
$("#enter").click(
  function() {
    var movie = $("#movie").val();
    var list = (movie);
    $('#list').append('<p>' + '<button id="vote"></button>' + list + '</p>');
  });

// The function that is supposed to place the chosen movies in a list below "Your best films"
$("#vote").click(
    function() {
    var voted = $("#best").val();
    var best = (voted);
    $('#best').append('<p>' + list + '</p>');
    });

所以第一个函数可以工作,只需要第二个函数。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-11-06 17:55:20

首先,不能从第二个函数中计算list。它超出了范围。所以你需要把它储存起来或者传递出去。我建议将它存储在按钮的值中。

工频:http://jsfiddle.net/Twisty/810353L9/

JQUERY

代码语言:javascript
复制
// The function that creates the first list
$("#enter").click(function () {
    var movie = $("#movie").val();
    var $btn = $('<button />', {
        id: "vote",
        type: "button",
        text: "^",
        value: movie,
        click: function(){
            var vote = this.value;
            $("#best").append('<p>'+vote+'</p>');
        }
    });
    var $p = $('<p />');
    //$('#list').append('<p>' + '<button id="vote" value="'+list+'">Vote</button> '+list+'</p>');
    $p.append($btn, " ", movie);
    $p.appendTo("#list");
});

// The function that is supposed to place the chosen movies in a list below "Your best films"
/*$("#vote").live('click', function () {
    var voted = $(this).attr("value");
    console.log(voted);
    $('#best').append('<p>' + voted + '</p>');
});*/

这将创建“投票”按钮,“投票”按钮将追加下一个列表。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33571251

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档