小编Fra*_*sca的帖子

jQuery中的意外标记

这个网站工作正常,但突然出现了错误.

意外的令牌( - 这意味着什么?看起来对我来说是正确的,并且已经好几个月了.

<script>
    function (){      <--"Uncaught SyntaxError: Unexpected token (" here
        $(".message").focus(function() {
            $("#bubble").fadeOut();
        }).blur(function() {
            $("#bubble").fadeIn();
        });
    })();
</script>
Run Code Online (Sandbox Code Playgroud)

javascript jquery

0
推荐指数
2
解决办法
180
查看次数

InnerHTML无法找到ID

它在JSFiddle中工作,但在我的代码中,innerHTML调用将无法工作,因为它似乎无法找到指定的ID.但我可以在页面上清楚地看到它.

该代码用于倒数计时器.这是代码:

<script>
// set the date we're counting down to
var target_date = new Date("Aug 15, 2019").getTime();

// variables for time units
var days, hours, minutes, seconds;

// get tag element
var countdownOpening = document.getElementById("countdownOpening");

// update the tag with id "countdownOpening" every 1 second
setInterval(function () {

    // find the amount of "seconds" between now and target
    var current_date = new Date().getTime();
    var seconds_left = (target_date - current_date) / 1000;

    // do some time calculations
    days = parseInt(seconds_left …
Run Code Online (Sandbox Code Playgroud)

jquery innerhtml

0
推荐指数
1
解决办法
205
查看次数

将类名添加到使用AJAX和PHP数组生成的范围

我无法理解为什么这种情况会持续下去.

我有一些存储在数组中的单词:

$poolOne=array("sparkly","sporty","happy","confident","awesome","funny","awkward","mad","silly","dynamic",
    "handsome","merry","horrid","funky","loud","chirpy","posh","clever","pretty","athletic");
Run Code Online (Sandbox Code Playgroud)

对此数组的调用会选择四个随机字并将其输出到a中 <span>

<?php foreach (array_rand($poolOne, 4) as $key) {
    echo "<span>".$poolOne[$key]."</span>";
}?>
Run Code Online (Sandbox Code Playgroud)

为了生成一个新的随机四个单词集而不刷新页面,我使用了一个非常简单的AJAX调用,只重新加载该部分,并为您提供一组新的四个单词.

你可以在这里看到这个,页面加载div中的代码wordbank,然后当运行AJAX(onClick绿色按钮)时,它再次从一个名为的文件加载相同的PHPwordbank.php

http://francesca-designed.me/create-a-status/index.php

这是标准的AJAX调用,没什么特别之处:

function refreshWords()
{
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("wordbank").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","wordbank.php",true);
xmlhttp.send();
}
Run Code Online (Sandbox Code Playgroud)

这一切都很好,你可以在上面的链接上看到.

但是下一步,我想使用jQuery UI来实现拖放的单词.这一步的第一步是将spans我的每个单词都放在一个类中,draggable这样jQuery可以做到这一点.但这是我遇到问题的地方.

一旦我添加class="draggable"到PHP调用,整个事情就会中断.

为什么只是简单地为这个调用添加一个类名呢?

这里没有

echo …
Run Code Online (Sandbox Code Playgroud)

html javascript php ajax draggable

0
推荐指数
1
解决办法
75
查看次数

按钮类型 CSS 和禁用按钮样式

这是我的按钮示例:

<button id="question_1a" disabled">Next question</button>
Run Code Online (Sandbox Code Playgroud)

我想将按钮的样式设置为标准样式,background-color如果禁用它们则不同:

input[type=button][disabled]{
    background-color:#CCC;
}
input[type=button]{
    background-color: #6CB300;
    color:#fff;
    border:0;
    font-size:1.5em;
    padding:2% 3%;
}
Run Code Online (Sandbox Code Playgroud)

这似乎不正确,如何选择禁用按钮和正常按钮?

html css css-selectors

0
推荐指数
1
解决办法
6231
查看次数

file_put_contents添加"0"而不是字符串

file_put_contents会添加0而不是传递给它的字符串是什么原因?

它为每次尝试提交文件添加0.所以000第三次尝试.

$masterpostEntry = $title . "~" . $filetitle;
$file = "../posts/master-allposts.txt";
$current = file_get_contents($file);
$current .= $masterpostEntry + "\n";
file_put_contents($file, $current);
Run Code Online (Sandbox Code Playgroud)

$ masterpostEntry的回显显示正确的结果:

CSS-Only Solution For UI Tracking~css-only-solution-for-ui-tracking
Run Code Online (Sandbox Code Playgroud)

但是master-allposts.txt的内容是:

000
Run Code Online (Sandbox Code Playgroud)

php

0
推荐指数
1
解决办法
105
查看次数

HTML5“日期”输入格式,自动填充当前日期

我使用的是 HTML5 日期格式,我想用当前日期自动填充它,但允许对其进行更改。

以前使用一个简单的文本框,我可以使用 PHP 来恢复表单上的当前日期,但仍然可以对其进行编辑,如下所示:

<input type="text" value="<?php echo date('d / m / Y'); ?>"/>
Run Code Online (Sandbox Code Playgroud)

但是当date用作输入类型时,PHP 值会被覆盖并替换为dd/mm/yyyy

<input type="date" value="<?php echo date('d / m / Y'); ?>"/>
Run Code Online (Sandbox Code Playgroud)

Tinygrab 截图示例

任何想法如何使用 HTML5 新输入类型但仍然能够提供默认值?

html date

0
推荐指数
1
解决办法
8821
查看次数

尽管初始化并传递给函数,变量仍未定义

不知道我哪里出错了.

我有以下代码,每1-2秒在页面上创建一个"气泡",然后在6秒后销毁每个气泡.

代码通常工作正常,除了尽管被初始化bubbleID显示的变量undefined.

function startBubbleMachine(){
        var bubbleID = 1;
        setInterval(function makeBubble(bubbleID){
            var wh = randomInt(143, 50);
            console.log('making bubble number '+bubbleID); // this shows undefined
            $('.wrapper').append('<div class="db-bubble db-bubble-'+bubbleID+'" style="transform:rotate('+randomInt(20, 1)+'deg);left:'+randomInt(100, 1)+'%;width:'+wh+'px;height:'+wh+'px;"></div>');
            killBubble(bubbleID);
            bubbleID++; // this doesn't seem to get used
        }, randomInt(2000, 1000));
    }
Run Code Online (Sandbox Code Playgroud)

我正在初始化bubbleID为1:

var bubbleID = 1;
Run Code Online (Sandbox Code Playgroud)

我正在传递bubbleID函数内部setInterval

setInterval(function makeBubble(bubbleID){
    ...
});
Run Code Online (Sandbox Code Playgroud)

然后我在该函数中递增它:

bubbleID++;
Run Code Online (Sandbox Code Playgroud)

我哪里错了?

javascript variables function

0
推荐指数
1
解决办法
49
查看次数

将其传递给 window.onscroll 函数

如何传递this给分配给我的事件的函数window.onscroll

我试图myFunction()在满足特定条件时触发。我需要检查这个情况onscroll

  init() {
    window.onscroll = function() {
      if(this.currentItemCount() > this.totalElements){
        this.totalElements = this.currentItemCount();
        this.myFunction();
      }
    };
  }
Run Code Online (Sandbox Code Playgroud)

this.currentItemCount()但是我收到一个不是函数的错误。我知道我需要传递thiswindow.onscroll但我无法弄清楚正确的语法。

javascript this ecmascript-6

0
推荐指数
1
解决办法
2335
查看次数

PHP如striplashes for forward slash?

是否有类似的选项来删除正斜杠?

我有一个文本输入,可以是任何斜杠:

例如/ slug // slugslug or slug /

我需要完全删除所有正斜杠,无论它们在哪里.我知道stripslashes会为\ slash执行此操作.前锋有什么类似的吗?

目前我有:

$successful_slug = stripslashes($input_successful_slug);
Run Code Online (Sandbox Code Playgroud)

php stripslashes

-1
推荐指数
1
解决办法
601
查看次数

session_start错误,因为同一session_start操作已“发送标题”?

我试图在PHP中启动一个会话,以便存储有关用户ID的数据(将在mySQL DB中使用)。

但是,当我开始会话时,出现以下错误:

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /Applications/MAMP/blah) in /Applications/MAMP/blah on line 38

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /Applications/MAMP/blah) in /Applications/MAMP/blah on line 38
Run Code Online (Sandbox Code Playgroud)

我了解错误是因为页面已提交或“标题已发送”而无法启动会话,但是我非常困惑,因为它所引用的行38行是启动会话的行:

Line 38: session_start();
Run Code Online (Sandbox Code Playgroud)

因此,如何说标头已经通过此行发送,这就是错误?

这是我的代码的简化部分。注意,HTML的一部分是通过jQuery使用AJAX加载的,是否可以?

<!DOCTYPE html>
<html>
<head>
<title>Title</title>
</head>
<body>
        <div class="wrapper">
          <div id="quiz-section">
             // This part is where the HTML content loads via AJAX
          </div>
        </div>
<!-- Below PHP looks at the referral …
Run Code Online (Sandbox Code Playgroud)

php session session-variables

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