小编Ale*_*lex的帖子

bootstrap模态在4秒后关闭或用户单击

如何为引导模式设置超时?获取ajax数据后,php返回的消息包含该术语success,我想给用户提供关闭窗口的选项.但是,我也只想减少4秒钟.目前第二个成功消息回来了,模态隐藏了自己.

$('#forgotform').submit(function (e) {
    "use strict";
    e.preventDefault();
    $('#forgotsubmit').button('loading');
    var post = $('#forgotform').serialize();
    var action = $('#forgotform').attr('action');
    $("#message").slideUp(350, function () {
        $('#message').hide();
        $.post(action, post, function (data) {
            $('#message').html(data);
            document.getElementById('message').innerHTML = data;
            $('#message').slideDown('slow');
            $('#usernamemail').focus();
            if (data.match('success') !== null) {
                $('#forgotform').slideUp('slow');
                $('#forgotsubmit').button('complete');
                $('#forgotsubmit').click(function (eb) {
                    eb.preventDefault();
                    $('#forgot-form').modal('hide');
                });
                setTimeout($('#forgot-form').modal('hide'), 10000);
            } else {
                $('#forgotsubmit').button('reset');
            }
        });
    });
});
Run Code Online (Sandbox Code Playgroud)

ajax jquery modal-dialog twitter-bootstrap

15
推荐指数
2
解决办法
5万
查看次数

项目排名,使用Reddit排名算法自信地排序

我有兴趣使用这个排名类,根据Evan Miller撰写的一篇文章来排名我有赞成票和downvotes的表.我有一个非常类似Stack Overflow的上/下投票系统的系统,用于我正在处理的事件站点,通过使用这个排名类,我觉得结果会更准确.我的问题是如何通过功能'hotness'订购?

private function _hotness($upvotes = 0, $downvotes = 0, $posted = 0) {
    $s = $this->_score($upvotes, $downvotes);
    $order = log(max(abs($s), 1), 10);

    if($s > 0) {
        $sign = 1;
    } elseif($s < 0) {
        $sign = -1;
    } else {
        $sign = 0;
    }

    $seconds = $posted - 1134028003;

    return round($order + (($sign * $seconds)/45000), 7);
}
Run Code Online (Sandbox Code Playgroud)

我想每次用户投票我都可以在我的表中有一个列,其中包含为新投票重新计算的热度数据,并按主页上的该列排序.但我有兴趣在运行中加入上述功能,我不确定这是否可行.

来自Evan Miller,他使用:

SELECT widget_id, ((positive + 1.9208) / (positive + negative) - 
                   1.96 * SQRT((positive * …
Run Code Online (Sandbox Code Playgroud)

php sorting algorithm ranking

8
推荐指数
1
解决办法
1312
查看次数

如何在我的网站中集成交易视图图表库

Iam建立了一个用于比特币交换的网站。我想使用在工作区中提取的交易视图图表库。我想知道如何提供自己的数据Feed。datafeed文件应采用哪种格式(例如php,js,json)?

var _datafeed = new Datafeeds.UDFCompatibleDatafeed("http://localhost/workspace/charting");
    //var _datafeed = new Datafeeds.UDFCompatibleDatafeed("https://demo_feed.tradingview.com");

    TradingView.onready(function () {
        var widget = window.tvWidget = new TradingView.widget({
            debug: true, // uncomment this line to see Library errors and warnings in the console
            fullscreen: false,
            symbol: 'A',
            interval: 'D',
            timezone: "America/New_York",
            container_id: "tv_chart_container",
            locale: getParameterByName('lang') || "en",
            datafeed: _datafeed,
            library_path: "charting_library/",
        });
    });
Run Code Online (Sandbox Code Playgroud)

在上面的代码中,图表是通过演示链接绘制的。当我将其更改为路径时,出现“无效符号”错误。我在哪里指定config和symbol_info以及它们的文件格式是什么?我是一个新手。请帮忙 。

任何以正确方式前进的建议都值得赞赏。我很烂!

错误消息的屏幕截图

javascript json tradingview-api

7
推荐指数
1
解决办法
7134
查看次数

何时使用 call_user_func_array

我已经阅读了堆栈上有关使用call_user_func_array与仅调用该函数的其他答案,但我仍然无法收集何时应使用前者。call_user_func_array我知道当您不知道传递了多少个参数时,您可能想要使用,因此您可以这样做: $args = func_get_args();...但是如果要在函数中使用参数,您是否总是需要知道参数?

以下两项工作,我认为第一个的开销较小。

$format = new Foo;
$method = 'somemethod';
$arg = 'somevalue';
if (method_exists($format, $method)) {
    return $format->$method($arg);
}
Run Code Online (Sandbox Code Playgroud)

return call_user_func_array(array($format, $method), array($arg));
Run Code Online (Sandbox Code Playgroud)

什么时候才能真正从使用中受益call_user_func_array

php call-user-func-array

5
推荐指数
1
解决办法
5284
查看次数

Lightbox facebook iframe,视频嵌入

我一直在尝试使用Magnific Popup(一个灯箱)加载facebook视频嵌入iframe.以前我使用的是PrettyPhoto,但是我想进行切换.奇怪的是,利用我在下面的代码中使用的相同方法,iframe无法正确加载(例如在播放器的范围内)用于Facebook.在此输入图像描述 我意识到PrettyPhoto正在发生同样的事情,我相信Facebook可能已经发生了变化.

<a class="video" href="http://www.facebook.com/video/embed/?_rdr=p&video_id=1291445700871053">Open Facebook video here</a>
Run Code Online (Sandbox Code Playgroud)

JS

$('.video').magnificPopup({
  type: 'iframe'
});
Run Code Online (Sandbox Code Playgroud)

有谁知道如何缓解这个问题?

http://codepen.io/afagard/pen/YWyoOP

javascript iframe jquery facebook magnific-popup

4
推荐指数
1
解决办法
2484
查看次数

jQuery验证插件和Bootstrap 4

我正在使用jQuery验证插件进行js表单验证。我还使用了Bootstrap4。我发现我需要修改,并进行修改errorPlacement,以便正确地以BS4样式显示验证错误。highlightunhighlight

$('#login-form').validate({
    rules: {
        login_username: {
            required: true
        },
        login_password: {
            required: true
        }
    },
    errorElement: 'span',
    errorPlacement: function (error, element) {
        error.addClass('invalid-feedback');
        element.closest('.form-group').append(error);
    },
    highlight: function (element, errorClass, validClass) {
        $(element).addClass('is-invalid');
    },
    unhighlight: function (element, errorClass, validClass) {
        $(element).removeClass('is-invalid');
    },
    submitHandler: function (form) {
        neou_cms.remove_error_messages();
        var username = form.elements['login_username'].value;
        var password = CryptoJS.SHA512(form.elements['login_password'].value).toString();
        login.login_user(username, password);
    }
});
Run Code Online (Sandbox Code Playgroud)

因此,对于每个功能,我都会重复这些属性。有没有“推”的方式验证库,这样我就不必重复errorPlacementhighlightunhighlight代码我每次使用验证?

jquery jquery-validate bootstrap-4

4
推荐指数
3
解决办法
7212
查看次数

更新mysql时间戳

我有一个带有字段的表:

'last_modified - timestamp NOT NULL'

  • 我将默认值设置为当前时间戳.但是这只适用于从phpMyAdmin更新或插入而不是从我的脚本更新或插入.

我试过了

$sql = sprintf("UPDATE %s SET timestamp=now(), %s WHERE id='%s'", $table, $implodeArray, $_POST['id']);
Run Code Online (Sandbox Code Playgroud)

它似乎仍然没有工作.当我从脚本中更新或插入表时,如何更新时间戳?

还有一个脚本输出示例:

UPDATE关于SET timestamp = now(),page_header ='页眉在这里',sub_header ='Sub header goes here',content_short ='这是关于about page的简短说明',content ='这是完整内容描述'WHERE id ='1'

php mysql timestamp

3
推荐指数
1
解决办法
2万
查看次数

数组翻转碰撞问题

是否有我不知道的函数/方法可以避免在翻转数组时删除类似的键。下面的例子:

原始数组:

Array ( [last_modified] => input [published] => input [project_content] => textarea ) 
Run Code Online (Sandbox Code Playgroud)

使用数组翻转(键碰撞):

Array ( [input] => published [textarea] => project_content )
Run Code Online (Sandbox Code Playgroud)

php arrays

3
推荐指数
1
解决办法
516
查看次数

select2成功获取新创建的标记id

在select2中,我有AJAX加载的标签,如果在db中找不到该标签,则用户可以选择创建一个新标签。问题在于,新标签在select2框中作为术语而不是ID列出(要选择的内容-如果仅由于术语而不是ID用户想要更新,则当再次加载标签时,尤其会成为问题存储在数据库中)。成功添加术语后,如何使select2接收ID并提交ID(而不是标签名称/术语)呢?

$(document).ready(function() {
var lastResults = [];
$("#project_tags").select2({
    multiple: true,
    placeholder: "Please enter tags",
    tokenSeparators: [","],
    initSelection : function (element, callback) {
        var data = [];
        $(element.val().split(",")).each(function () {
            data.push({id: this, text: this});
        });
        callback(data);
    },
    ajax: {
        multiple: true,
        url: "framework/helpers/tags.php",
        dataType: "json",
        data: function(term) {
            return {
                term: term
            };
        },
        results: function(data) {
            return {
                results: data
            };
        }
    },
    createSearchChoice: function(term) {
        var text = term + (lastResults.some(function(r) {
            return r.text == term
        }) ? …
Run Code Online (Sandbox Code Playgroud)

php ajax jquery jquery-select2

2
推荐指数
1
解决办法
1324
查看次数

AJAX表单提交成功处理程序的问题

我遇到一个问题,我的AJAX表单帖子创建了一个警报,似乎回显整个页面,而不仅仅是成功消息,我无法弄清楚我做错了什么.另外,我已经跟踪了很多关于堆栈的技巧,通过序列化传递数据,但是我习惯了这样的事情,data { action: add, type: new }并且我有问题将其他变量附加到post请求到数据,因为$(this).serialize();

PHP

if (isset($_POST['type']) && $_POST['type'] == 'email') {
    $emailFrom = EMAIL_FROM;
    $email_to = $_POST['email_to'];
    $subject = $_POST['subject'];
    $body = $_POST['body'];
    if (mail($email_to, $subject, $body, "From: <$emailFrom>")) {
        return 'Email was successfully sent!';
    } else {
        return 'An error occured, email could not be sent.';
    }
    exit();
}
Run Code Online (Sandbox Code Playgroud)

JS

 <script>
    $(document).ready(function() {
        $("#user_email").submit(function(e) {
            var subject = $('#subject').val();
            var _body = $('#body').val();
            if (_body && subject) {
                $.ajax({ …
Run Code Online (Sandbox Code Playgroud)

php ajax jquery

2
推荐指数
1
解决办法
125
查看次数