【发布时间】:2011-01-08 20:13:36
【问题描述】:
我一直在关注tutorial 使用 PHP 和 jQuery 创建样式切换器,现在在教程中 PHP 函数使用获取数据,这在 codeigniter 中不可用,我希望有人能够帮助我整理对不起尝试?
我的 PHP 函数
function setBackground() {
$style = $this->uri->segment(3);
setcookie("style", $style, time() + (60*60*24*30));
echo $style;
}
我的 HTML 和 jquery 调用
<ul id="options">
<li><a class="option" href="<?php echo base_url();?>welcome/setBackground/red">Red</a></li>
<li><a class="option" href="<?php echo base_url();?>welcome/setBackground/green">Green</a></li>
</ul>
<script type="text/javascript">
$('a.option').styleSwitcher(); // calling the plugin
</script>
jQuery 插件
jQuery.fn.styleSwitcher = function(){
$(this).click(function(){
loadStyleSheet(this);
return false;
});
function loadStyleSheet(obj) {
$('body').append('<div id="overlay" />');
$('body').css({height:'100%'});
$('#overlay')
.css({
display: 'none',
position: 'absolute',
top:0,
left: 0,
width: '100%',
height: '100%',
zIndex: 1000,
background: 'black url(img/loading.gif) no-repeat center'
})
.fadeIn(500,function(){
$.get( obj.href+'&js',function(data){
$('#stylesheet').attr('href','/media/css/' + data + '.css');
cssDummy.check(function(){
$('#overlay').fadeOut(500,function(){
$(this).remove();
});
});
});
});
}
var cssDummy = {
init: function(){
$('<div id="dummy-element" style="display:none" />').appendTo('body');
},
check: function(callback) {
if ($('#dummy-element').width()==2) callback();
else setTimeout(function(){cssDummy.check(callback)}, 200);
}
}
cssDummy.init();
}
单击链接以更改样式表时,我通过 firebug 得到此错误,
遇到错误
您提交的 URI 包含不允许的字符。
正在发送的网址是,
http://mywebsite/index.php/welcome/setBackground/green&js
这个例子是我点击绿色选项。
【问题讨论】:
标签: php css codeigniter jquery-plugins jquery