Jquery错误通过get发送十六进制代码

时间:2014-03-06 06:42:42

标签: javascript php jquery colors get

这是我的代码......

var o_color ='<?php echo $o_color;?>'; //i have also tried urlencode($o_color)
var o_color1 ='';

此代码工作正常....

   window.location.href = site+"name="+$(this).attr('id')+'&o_color='+o_color;

但此代码不起作用....

   window.location.href = site+"name="+$(this).attr('id')+'&o_color='+o_color+'&o_color1='+o_color1;

Note:o_color is in hexa code #e34343;

我在控制台日志上收到一条jquery错误消息......

Uncaught Error: Syntax error, unrecognized expression: a[rel=123123&o_color1=] 

2 个答案:

答案 0 :(得分:2)

尝试从"o_color"

中删除双引号
window.location.href = site+"name="+$(this).attr('id')+'&o_color='+ o_color +'&o_color1='+o_color1;

记录你必须: -

<script>
var site='http://localhost/new/';
var o_color = '#e34343';
var o_color1 = '';
window.location.href = site+'name=dfg&o_color='+o_color+'&o_color1='+o_color1;
</script>

答案 1 :(得分:2)

window.location.href = site+"name="+$(this).attr('id')+"&o_color="+o_color+"&o_color1="+o_color1;

根据你

<script>
var site='http://localhost/new/';
var o_color = '#e34343';
var o_color1 = '';
window.location.href = site+'name=dfg&o_color='+o_color+'&o_color1='+o_color1;
</script>