我正在使用jQuery 1.6.1。这是主要代码:
<div>Sidebar (on/off): <input id="sidebar" name="Sidebar" type="checkbox" value="value1"/></div>
<?php if ($row_rsPage['fullcontent']==1)
{ ?>
<div id="site_layout_full">
<?php
$oFCKeditor = new FCKeditor('FCKeditor1');
$oFCKeditor -> BasePath = 'fckeditor/';
$oFCKeditor -> Height = '455';
$oFCKeditor -> Value = $row_rsPage['pg_cont'];
$oFCKeditor -> Create();
?>
</div>
<?php } else { ?>
<div id="site_layout_content">
<?php
$oFCKeditor = new FCKeditor('FCKeditor1');
$oFCKeditor -> BasePath = 'fckeditor/';
$oFCKeditor -> Height = '455';
$oFCKeditor -> Value = $row_rsPage['pg_cont'];
$oFCKeditor -> Create();
?>
</div>
<div id="site_layout_sidebar">
<?php
$oFCKeditor2 = new FCKeditor('FCKeditor2');
$oFCKeditor2 -> BasePath = 'fckeditor/';
$oFCKeditor2 -> Config['CustomConfigurationsPath'] = '../sidefckconfig.js' ;
$oFCKeditor2 -> ToolbarSet = 'Short';
$oFCKeditor2 -> Height = '455';
$oFCKeditor2 -> Value = $row_rsPage['pg_sidecont'];
$oFCKeditor2 -> Create();
?>
</div>
$row_rsPage['fullcontent']==1
只显示1个div(site_layout_full
),当它不显示时会显示2个div(site_layout_content
和site_layout_sidebar
)。
现在我要做的是在不提交页面并将值存储到数据库中的情况下切换它。
所以我使用侧边栏来切换状态但是如何将这个值输入MySQL。
最初,这可以在没有AJAX的情况下提交表单,然后将其存储在数据库中。但我希望它是交互式的,这样你就不必提交整个页面来改变布局的变化。
我用它来切换(但不起作用):
if (document.getElementById('sidebar').checked) {
// display fullcontent
document.getElementById('site_layout_sidebar').style.display = 'none';
document.getElementById('site_layout_content').style.display = 'none';
document.getElementById('site_layout_full').style.display = 'block';
}
else {
// display site_content, site_sidebar
document.getElementById('site_layout_full').style.display = 'none';
document.getElementById('site_layout_content').style.display = 'block';
document.getElementById('site_layout_sidebar').style.display = 'block';
}
如何将此值(复选框的状态)存储到$row_rsPage['fullcontent']
?
$fullcontent
为0
$fullcontent
为1
有人可以帮忙解决这个问题吗?
我改变了这个: 在javascript周围添加了$(document).ready(function(){}。这会触发事件,但我隐藏了div标签site_layout_full,因为数据库中的每个条目都将fullcontent设置为0
所以我实际上隐藏了div标签,无法再显示它。
我必须用javascript检查数据库然后切换但是如何?
所以我可以这样做:
document.getElementById('site_layout_full').style.display = 'none';
document.getElementById('site_layout_content').style.display = 'block';
document.getElementById('site_layout_sidebar').style.display = 'block';
并摆脱if ($row_rsPage['fullcontent']==1)
?
总结一下,我必须:
怎么样?
答案 0 :(得分:1)
这是部分答案。有一些问题,但我还没有找到它:
Javascript / ajax代码:
$(document).ready(function() {
$pageid = document.getElementById('pg_id').value;
$.post("senddata.php",{ id: $pageid },function (ContentFull) {
alert("DATA = " + ContentFull);
if (ContentFull==0) // 1 = Fullcontent - 0 = sidebar
{
$('input[name=Sidebar]').attr('checked', true);
} else {
$('input[name=Sidebar]').attr('checked', false);
}
});
$('#sidebar').change(function(){
$('#site_layout_sidebar').toggle();
$('#site_layout_content').toggle();
$('#site_layout_full').toggle();
});
if (document.getElementById('sidebar').checked) {
// display fullcontent
document.getElementById('site_layout_full').style.display = 'none';
document.getElementById('site_layout_content').style.display = 'block';
document.getElementById('site_layout_sidebar').style.display = 'block';
}
else {
// display site_content, site_sidebar
document.getElementById('site_layout_full').style.display = 'block';
document.getElementById('site_layout_content').style.display = 'none';
document.getElementById('site_layout_sidebar').style.display = 'none';
}
});
这是senddata.php:
$pid = $_POST['id'];
mysql_select_db($database_conndb, $conndb);
$query_Recordset1 = "SELECT tbl_pages.pg_id, tbl_pages.fullcontent FROM tbl_pages WHERE tbl_pages.pg_id='$pid'";
$Recordset1 = mysql_query($query_Recordset1, $conndb) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
$ContentFull = $row_Recordset1['fullcontent'];
echo($ContentFull);
mysql_free_result($Recordset1);
现在我从请求中得到了正确的数据,但我认为某处存在错误.... 即使Alert DATA给出了我0
,我似乎总是得到完整的内容布局我做错了什么......