我正在尝试编写一个代码,在用户单击在幻想框内找到的选项之一后,文本将出现在可以在幻想框外看到的 div 中(选择一个选项后,幻想框将关闭)
这是我的代码
索引.php
<?php
session_start();
include('connect.php');
include('header.php');
?>
<body>
<a href="selectfield.php" id="selectfield" class="fancybox.iframe" rel="group">Field</a>:
<span id="selectedfield_label"></span>
</body>
</html>
选择字段.php
<?php
include('connect.php');
include('header.php');
?>
</head>
<body>
<div class="row">
<div class="span12">
<?php
$searchcol = mysql_query("SELECT * from searchcolumn");
while($search = mysql_fetch_array($searchcol)){ ?>
<div class="span2" style="font-size:10px">
<a href="#" id="<?php echo $search['scol_id']; ?>" class="field" name="<?php echo $search['scol_id']; ?>"><?php echo $search['advsearch_name']; ?></a>
</div>
<?php
}
?>
</div>
</body>
</html>
脚本.js
$(document).ready(function(){
$("#selectfield").fancybox();
$("#selectcondition").fancybox();
$(".field").click(function(e) {
var id = this.id;
var name = $("#" + id).attr("name");
var datastr='field='+name;
$.ajax({
url:'storefield.php',
type:"POST",
data:datastr,
dataType:"json",
success:function(result){
$("#selectedfield_label").html(result['field']['fieldname']);
parent.$.fancybox.close(true);
}//success
});//ajax
});
});
storefield.php
<?php
session_start();
include('connect.php');
$scol_id=$_POST['field'];
$query = mysql_query("SELECT * from searchcolumn where scol_id = $scol_id");
$a = mysql_fetch_array($query);
$_SESSION['fieldname'] = $a['advsearch_name'];
$_SESSION['col'] = $a['advsearch_col'];
$_SESSION['type'] = $a['advsearch_type'];
$result['field']['fieldname'] = $_SESSION['fieldname'];
$result['field']['col'] = $_SESSION['col'];
$result['field']['type'] = $_SESSION['type'];
echo json_encode($result);
?>
我能够在选择一个选项时关闭fancybox,但我无法让它的名称($result['field']['fieldname'])出现在我的fancybox外部的div内
我已经尝试过不同的组合,但我无法让它工作
提前致谢
这是一个示例 sql 数据
INSERT INTO searchcolumn (advsearch_name,advsearch_col,advsearch_type) VALUES ('Title','title','varchar');
INSERT INTO searchcolumn (advsearch_name,advsearch_col,advsearch_type) VALUES ('Last Name','ln','varchar');
INSERT INTO searchcolumn (advsearch_name,advsearch_col,advsearch_type) VALUES ('First Name','fn','varchar');
INSERT INTO searchcolumn (advsearch_name,advsearch_col,advsearch_type) VALUES ('Middle Name','mn','varchar');
INSERT INTO searchcolumn (advsearch_name,advsearch_col,advsearch_type) VALUES ('Gender','gender','varchar');
INSERT INTO searchcolumn (advsearch_name,advsearch_col,advsearch_type) VALUES ('Age','age','varchar');
INSERT INTO searchcolumn (advsearch_name,advsearch_col,advsearch_type) VALUES ('Birthdate','bday','date');