Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/367.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在javascript中显示和隐藏文本而不是使用警报?_Javascript_Jquery - Fatal编程技术网

如何在javascript中显示和隐藏文本而不是使用警报?

如何在javascript中显示和隐藏文本而不是使用警报?,javascript,jquery,Javascript,Jquery,下面是用于上下投票点击功能的javascript: <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_wra

下面是用于上下投票点击功能的javascript:

<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); 
                $('#'+unique_id+' .down_votes').text(response.vote_down);
            },'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==='down_button') //user disliked the content
        {
            //prepare post content
            post_data = {'unique_id':unique_id, 'vote':'down'};

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

                //replace vote down count text with new values
                $('#'+unique_id+' .down_votes').text(data);

                //thank user for the dislike
                alert("Thanks! Each Vote Counts, Even Dislikes!");

            }).fail(function(err) { 

            //alert user about the HTTP server error
            alert(err.statusText); 
            });
        }
        else 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
                alert("Thanks! For Liking This Content.");
            }).fail(function(err) { 

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

    });
//end 

});
</script>

$(文档).ready(函数(){
//#######在页面加载时,检索每个内容的投票
$.each($('.voting_wrapper'),function(){
//从此投票包装器元素中检索唯一id
var unique_id=$(this.attr(“id”);
//准备帖子内容
post_data={'unique_id':unique_id,'vote':'fetch'};
//使用jQuery$.post()将数据发送到“vote_process.php”
$.post('vote\u process.php',post\u数据,函数(响应){
//从服务器检索投票,替换每个计票文本
$(“#”+唯一的_id+”.up_votes').text(response.vote_-up);
$(“#”+唯一的_id+”.down_votes').text(response.vote_down);
}“json”);
});
//#######单击按钮,获取用户投票并使用jQuery$.post()将其发送到vote_process.php。
$(“.voting\u wrapper.voting\u btn”)。单击(函数(e){
//获取所单击元素的类名(向下/向上按钮)
var clicked_button=$(this.children().attr('class');
//从父元素中获取唯一ID
var unique_id=$(this.parent().attr(“id”);
如果(单击按钮==='down按钮')//用户不喜欢该内容
{
//准备帖子内容
post_data={'unique_id':unique_id,'vote':'down';
//使用jQuery$.post()将数据发送到“vote_process.php”
$.post('vote\u process.php',post\u数据,函数(数据){
//用新值替换投票倒计时文本
$(“#”+唯一的_id+”.down_voces')。文本(数据);
//感谢用户的不喜欢
警惕(“谢谢!每一张选票都很重要,甚至不喜欢!”);
}).fail(函数(err){
//提醒用户HTTP服务器错误
警报(错误状态文本);
});
}
else if(单击按钮==='up\u按钮')//用户喜欢该内容
{
//准备帖子内容
post_data={'unique_id':unique_id,'vote':'up'};
//使用jQuery$.post()将数据发送到“vote_process.php”
$.post('vote\u process.php',post\u数据,函数(数据){
//用新值替换向上投票计数文本
$(“#”+唯一的_id+”.up_vots')。文本(数据);
//感谢用户喜欢的内容
提醒(“谢谢!喜欢这个内容。”);
}).fail(函数(err){
//提醒用户HTTP服务器错误
警报(错误状态文本);
});
}
});
//结束
});
html:


0
单击按钮时,将显示文本作为警报框

我可以知道,如何像动画一样显示文本和隐藏

我需要当我点击按钮时,它显示“你投票了”,然后隐藏


有人能帮我吗?提前感谢。

您想要使用的是模态/弹出/对话框。您有一个在引导中使用modal的示例。您只需将代码中的
alert()
替换为正确使用的模式窗口即可。

您需要创建一个带有id的div,并将其放在要显示文本的位置。然后,您可以用以下内容替换警报语句

$('myDiv').text('mytext!')


$('myDiv').innerHtml('mytext!')

单击按钮时,创建一个div容器并显示它。 然后等待2000毫秒,然后淡出

$("#myButton").click(function() {
        var myAlert = $('<div />').addClass("alert alert-success").html("test");
        $("body").append(myAlert);
        setTimeout(function() {
            $(myAlert).fadeOut();
        },2000);
    });
$(“#我的按钮”)。单击(函数(){
var myAlert=$('').addClass(“警报成功”).html(“测试”);
$(“正文”)。追加(myAlert);
setTimeout(函数(){
$(myAlert).fadeOut();
},2000);
});

谢谢。。但是如何处理我现有的源代码呢?只需将其替换为您的
警报(“谢谢!喜欢此内容”)谢谢,。我可以知道大约200毫秒后的隐藏吗?如何编辑我的代码?。。我是jquery的新手。。例如,像这样感谢:setTimeout(function(){$('#mydiv').fadeOut('fast');},1000);你还应该看看alertify.js:你能看看我的最新帖子吗,从那怎么做到这一点?。。我正在努力添加您的代码。谢谢
$("#myButton").click(function() {
        var myAlert = $('<div />').addClass("alert alert-success").html("test");
        $("body").append(myAlert);
        setTimeout(function() {
            $(myAlert).fadeOut();
        },2000);
    });