sac*_*god 0 javascript ruby-on-rails
我在 app/views/reports 下有一个名为 _report_js.html.erb 的 javascript 文件。当我运行我的应用程序时,我收到错误:
类型错误:$.url 不是函数
这是我的代码:
<script type="text/javascript">
if($.url().param('ig') == 'true') {
alert("hi");
$('#icons').hide();
$('#photos').show();
end
</script>
Run Code Online (Sandbox Code Playgroud)
小智 5
$.url()
Run Code Online (Sandbox Code Playgroud)
不是 jQuery 核心的一部分。如果你想实现类似的东西,也许使用
var getUrlParameter = function getUrlParameter(sParam) {
var sPageURL = decodeURIComponent(window.location.search.substring(1)),
sURLVariables = sPageURL.split('&'),
sParameterName,
i;
for (i = 0; i < sURLVariables.length; i++) {
sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] === sParam) {
return sParameterName[1] === undefined ? true : sParameterName[1];
}
}
};
Run Code Online (Sandbox Code Playgroud)
使用它:
var tech = getUrlParameter('technology');
Run Code Online (Sandbox Code Playgroud)
在你的例子中,它会是这样的
if(getUrlParameter('ig') == 'true') {
Run Code Online (Sandbox Code Playgroud)