gpt4 book ai didi

javascript - Jquery concatination 与 upvotes 在 php

转载 作者:行者123 更新时间:2023-11-30 17:01:53 26 4
gpt4 key购买 nike

我已经使用 php 和 jquery 创建了投票系统。

这是我的 index.php:

<script type="text/javascript" src="js/jquery-1.9.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {

//####### on page load, retrive votes for each content
$.each( $('.voting_wrapper'), function(){

//retrive unique id from this voting_wrapper element
var unique_id = $(this).attr("id");

//prepare post content
post_data = {'unique_id':unique_id, 'vote':'fetch'};

//send our data to "vote_process.php" using jQuery $.post()
$.post('vote_process.php', post_data, function(response) {

//retrive votes from server, replace each vote count text
$('#'+unique_id+' .up_votes').text(response.vote_up);
},'json');
});



//####### on button click, get user vote and send it to vote_process.php using jQuery $.post().
$(".voting_wrapper .voting_btn").click(function (e) {

//get class name (down_button / up_button) of clicked element
var clicked_button = $(this).children().attr('class');

//get unique ID from voted parent element
var unique_id = $(this).parent().attr("id");


if(clicked_button==='up_button') //user liked the content
{
//prepare post content
post_data = {'unique_id':unique_id, 'vote':'up'};

//send our data to "vote_process.php" using jQuery $.post()
$.post('vote_process.php', post_data, function(data) {

//replace vote up count text with new values

$('#'+unique_id+' .up_votes').text(data);
//thank user for liking the content
dataModified = data+' users has voting including you';
$('#message-status').hide().html(dataModified).fadeIn('slow').delay(5000).hide(1);
}).fail(function(err) {

//alert user about the HTTP server error
alert(err.statusText);
});
}

});
//end

});

</script>
<style type="text/css">
<!--
.content_wrapper{width:500px;margin-right:auto;margin-left:auto;}
h3{color: #979797;border-bottom: 1px dotted #DDD;font-family: "Trebuchet MS";}

/*voting style */
.voting_wrapper {display:inline-block;margin-left: 20px;}
.voting_wrapper .up_button {background: url(images/index.png) no-repeat;float: left;width: 50px;cursor:pointer;}
.voting_wrapper .up_button:hover{background: url(images/index.png) no-repeat;}
.voting_btn{float:left;margin-right:5px;}
.voting_btn span{font-size: 11px;float: left;margin-left: 3px;}

-->
</style>
</head>

<body>
<div class="content_wrapper">
<h3><img src="9780143332497.jpg" alt=""><br />

<!-- voting markup -->
<div class="voting_wrapper" id="1001">
<div class="voting_btn">
<div class="up_button">&nbsp;</div><span class="up_votes"></span>
</div>
</div>
<!-- voting markup end -->
</h3>
<span id="message-status"></span>
</div>

当我点击评分按钮时,它会显示稳定的计数,并且我设置为显示投票计数淡入和淡出。

现在我需要这样的http://s1.postimg.org/mv060km8v/Untitled_1.png

我试图在我的 jquery 脚本中添加我的“用户已投票”文本,但似乎没有任何反应。

请问我在哪里可以添加准确的代码来满足我的需求?

谁能帮帮我?提前致谢。

最佳答案

在你的 index.php 中

//retrive votes from server, replace each vote count text
$('#'+unique_id+' .up_votes').text(response.vote_up + ' user has voted');

您在 jquery 中单独添加计数,尝试将文本与其一起添加。

关于javascript - Jquery concatination 与 upvotes 在 php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28688704/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com