【问题标题】:javascript - unexpected token?javascript - 意外的令牌?
【发布时间】:2018-06-30 19:19:26
【问题描述】:

我想在上传照片时添加加载 gif。 这是我的 JavaScript:

<script type="text/javascript">
    function call(tab) {
        $(".loading").html("<center><br><br><img src=\"icons/processing.gif\" /><br><br></center>").load(tab);

    }
</script>

这就是我调用函数的方式:

<div class="loading"></div>
    <div class="col-md-12">
        <div class="form-group">
            <input type="file" name="take_photo" id="take_photo" class="take-photo" onchange="submit(); call('survey_edit.php?id='<?$id;?>'&step=photo')">
            <label for="take_photo"><figure><img src="icons/camera.png"></figure> <span><?=v("take_photo");?>&hellip;</span></label>
        </div>
        <div class="form-group">
            <?=$f->input("back",v("back"),"type='button' onclick=\"window.location='?step=2&id=".$id."';\"","btn btn-warning");?>
            <?=$f->input("finish",v("finish"),"type='button' onclick=\"window.location='mysurvey.php';\" style='position:relative;float:right;'","btn btn-primary");?>
        </div>
    </div>

它显示以下错误:“Uncaught SyntaxError: Unexpected token ?”

谁能帮我解决这个问题?

【问题讨论】:

  • 您的源代码在 .form-group 中看起来有问题。此外,center 早已被弃用。有更好的方法来做这些更新。里面有那个PHP吗?可能是您的网络服务器设置不正确。
  • 第二部分是php吗?如果是这样,则显示发送到服务器的最终 html 代码。但最有可能的错误是在这里 ?id='&lt;?$id;?&gt;'&amp;step= ' 之前 &lt;? 将结束 js 中的字符串,然后将字符串 (&lt;) 与 ? 进行比较,然后 ? 是意外的令牌。
  • @t.niese 我也刚刚意识到 PHP。
  • @t.niese 感谢您的解释,错误很明显,但我的加载 gif 尚未显示。有什么建议吗?
  • @payket 这是一个不同的问题,因此必须作为新问题提出。

标签: javascript html css


【解决方案1】:

根据评论,问题出在这一行:

<input type="file" name="take_photo" id="take_photo" class="take-photo" onchange="submit(); call('survey_edit.php?id='<?$id;?>'&step=photo')">

这里的问题是&lt;?之前的'会在js中结束字符串,而&lt;?应该是&lt;?=,否则&lt;?$i?&gt;不会被php替换为值为$i.

然后将字符串 (&lt;) 与 ? 进行比较,然后 ? 是一个意外标记。

<input type="file" name="take_photo" id="take_photo" class="take-photo" onchange="submit(); call('survey_edit.php?id=<?=$id;?>&step=photo')">

【讨论】:

    【解决方案2】:

    您的 onchange 事件应如下所示:

    onchange="submit(); call('survey_edit.php?id=&lt;?=$id?&gt;&amp;step=photo')"

    【讨论】:

      猜你喜欢
      • 2014-11-29
      • 2015-06-11
      • 1970-01-01
      • 2021-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多