javascript - 如何在 Javascript 上正确获取我的 url 参数?
问题描述
我正在尝试将 giphy url 解析为 javascript 参数,它会删除我所有的 //.
这是我的js:
var $save = $("<input type=\"button\" class=\"btn btn-sm btn-success\" value=\"Save\" onclick=\"SaveGif(\"" + gif.fixed_height.url +"\")\" />");
网址是:
这就是 Chrome 解析的内容:
<input type="button" class="btn btn-sm btn-success" value="Save" onclick="SaveGif(" https:="" media1.giphy.com="" media="" tjqyalvo9ahykfykaj="" 200.gif?cid="487fb615lw0p7lcstn5iqghh0mxvk4n889nope6ven1n897i&rid=200.gif")"">
此外,如果我删除引号,我会得到正确的 url,但没有“”:
<input type="button" class="btn btn-sm btn-success" value="Save" onclick="SaveGif(https://media1.giphy.com/media/tJqyalvo9ahykfykAj/200.gif?cid=487fb615lw0p7lcstn5iqghh0mxvk4n889nope6ven1n897i&rid=200.gif)">
我做错了什么?
谢谢!
解决方案
使用单引号
var $save = $("<input type=\"button\" class=\"btn btn-sm btn-success\" value=\"Save\" onclick=\"SaveGif('" + gif.fixed_height.url + "')\" />");
推荐阅读
- mysql - 如何使用触发器防止插入表
- java - 什么实现更有效地计算数字样本中的出现次数?
- python - 在 Python 中使用 Twilio 接收和处理 SMS
- python - 'WSGIRequest' 对象没有属性 'session' 和 'user'
- python - Python在txt文件中搜索输入
- javascript - 语法错误:意外的令牌,预期的 { (1:7) ,create-react-app
- python - 从元组中提取边集
- apl - 将函数应用于矩阵的随机行
- javascript - 如何禁用向左滚动?
- javascript - 我的 findOutlier 函数有什么问题?为什么我会出错?