投票

<script>
$(function(){
    insertContent('5247','1');
    insertContent('5254','2');
    $("#subSelect").click(function(){
        var _vote_id= $('input[name="vote_id[]"]');
        var voteId = setStr(_vote_id);
        var num = _vote_id.size();
        var opt ='';
        _vote_id.each(function(index) {
            var t = index+1;
            if($('input[name="option'+t+'"]:checked').size()==0){
                alert ('投票不能为空!');
                return false ;
            }else{
                opt += '|' +$('input[name="option'+t+'"]:checked').val() ;
            }
        })
        opt = opt.substring(1,opt.length);
        $.post("/Api/insertVote/", {module : 'article',vote_id : voteId,option_id : opt}, function (a){
                alert(a.info);
        },"json");
    })
})
function setStr(obj){
    var str="";
    var count = obj.size();
    obj.each(function(index) {
        str += $(this).val();
        if(index != (count-1)){
            str += '|';
        }
    });
    return str;
}
function insertContent(voteId,n){
var chooseX = 'choose'+n;
$("#addChoose").append("<dl><pre></pre><dt id='"+chooseX+"'></dt></dl>");
$.post("/Api/viewVote/","vote_id="+voteId,function(json){
        var  arr = json.data.option;
        $(".moods").html("人气值:"+json.data.count_all);
        $("#choose"+n).html(n+"、"+json.data.title+"<em>(必选)</em>");
        for(var i=0; i<arr.length;i++){
            var num  = parseInt((arr[i]['count']/json.data.count_all)*100);
            var count  =  isNaN(parseInt(arr[i]['count']))  ? 0 : arr[i]['count'] ;
            var optionx = 'option'+n;
            var s = GetRandom(9);
            $("#choose"+n).parent().append('<dd><input type="radio" class="radio" value="'+arr[i]['id']+'" name="'+optionx+'"/><em class="t">'+arr[i]['title']+'</em><em class="buoy"><cite class="s'+s+'" style="width:'+num+'%;"><i></i></cite></em><em>'+count+' ('+num+'%)</em></dd>');
        }
        $("#choose"+n).parent().append('<input type="hidden" name="vote_id[]" value="'+json.data.id+'">');
    },'json')

}
function GetRandom(n){
    return Math.floor(Math.random()*n+1);
}
</script>
<div id="wrap">
    <div id="header"><a href="javascript:void(0)" class="logo" title="腾讯家居">腾讯家居</a></div>
    <div id="mainbody">
        <h1 class="title">腾讯家居_宠物家居网络调查</h1>
        <h3 class="moods"></h3>
        <div class="list" id="addChoose">
        </div>
        <p class="submit"><input type="button" id="subSelect"/></p>
    </div><!--/mainbody-->
</div><!--/wrap-->
 

你可能感兴趣的:(职场,休闲,投票)