我有一个带垂直菜单的主页面名称。当我单击其中一个搜索菜单时,它会动态地在我的内容上加载表单。
这是第一个表格。
<?php echo validation_errors(); ?>
<?php
$attr = array(
'class' => 'search_user'
);
echo form_open('controller/function', $attr);
?>
<p>Username or Email:
<input type="text" name="user_mail" size="30"/>
</p>
<p> Within:
<select name="by_search" id="select">
<option value="reg" <?php echo set_select('by_search','reg'); ?> > Registered </option>
<option value="non_reg" <?php echo set_select('by_search','non_reg'); ?> > Non Registered </option>
</select> </p>
<p> <input type="submit" name="submit" id="submit" value="Submit Search" /></p>
<!-- end .content --></div>
<!-- end .container </div> -->
</form>
<script type="text/javascript" src="<?php echo base_url(); ?>js/content.js"></script>
提交此表单后,会显示此表单;
<div class="content">
<?php echo validation_errors(); ?>
<?php
$attributes = array(
'class' => 'registered'
);
echo form_open('controller/function',);
?>
<h2>User Management Panel</h2>
<p>Username or Email:
<input type="text" name="user_mail" size="30"/>
</p>
<p> Within:
<select name="by_search" id="select">
<option value="reg" <?php echo set_select('by_search','reg'); ?> > Registered </option>
<option value="non_reg" <?php echo set_select('by_search','non_reg'); ?> > Non Registered </option>
</select> </p>
<p><input type="submit" name="button" id="button" value="Submit Search" /></p>
<table width="630px" style=" margin-left:10px" cellspacing="2" cellpadding="2" border="1" align="center" >
<tr bgcolor="#CCCCCC" >
<td width="40px" align="center" ><font face="Arial, Helvetica, sans-serif">id</font></td>
<td width="80px" ><font face="Arial, Helvetica, sans-serif"> Username</font></td>
<td width="80px" ><font face="Arial, Helvetica, sans-serif"> First Name</font></td>
<td width="80px" ><font face="Arial, Helvetica, sans-serif">Last Name</font></td>
<td width="80px" ><font face="Arial, Helvetica, sans-serif">Status</font></td>
</tr>
<?php
foreach($query as $row){
?>
<tr>
<td align="center" ><font face="Arial, Helvetica, sans-serif"><?php print $row->id; ?></font></td>
<td ><font face="Arial, Helvetica, sans-serif"><?php echo "<a href= 'user_manage/user/$row->username';" ?>><?php print $row->username; ?> </a> </font></td>
<td ><font face="Arial, Helvetica, sans-serif"><?php print $row ->firstname; ?></font></td>
<td ><font face="Arial, Helvetica, sans-serif"><?php print $row ->lastname; ?></font></td>
<td ><font face="Arial, Helvetica, sans-serif"><?php print $row ->status; ?></font></td>
<?php }?>
</tr>
</table>
<!-- end .content --></div>
<!-- end .container </div> -->
</form>
<script type="text/javascript" src="<?php echo base_url(); ?>js/content.js"></script>
这是我的content.js
$('a.webwidget_vertical_menu').click(function(){
var linkme = $(this);
var url = linkme.attr("href");
$(".content").load(url);
return false;
});
$(".search_user").submit(function(){
//alert("capture test");
var frm = $(".search_user");
$.ajax({
type: frm.attr("method"),
url: frm.attr("action"),
data: frm.serialize(),
success: function(data){
$(".content").html(data);
},
error:function(xhr,err){
alert("readyState: " +xhr.readyState + "\nstatus: " +xhr.status);
alert("responseText: "+ xhr.responseText);
}
});
return false;
});
$(".registered").submit(function(){
//alert("capture test");
var frm = $(".registered");
$.ajax({
type: frm.attr("method"),
url: frm.attr("action"),
data: frm.serialize(),
success: function(data){
$(".content").html(data);
},
error:function(xhr,err){
alert("readyState: " +xhr.readyState + "\nstatus: " +xhr.status);
alert("responseText: "+ xhr.responseText);
}
});
return false;
});
似乎我的.registered提交没有阅读或工作,因为我尝试了警报,它甚至没有去那里。当我单击第二个表单上的提交时,只显示内容,页面的其他元素消失了。我的目标是使我的内容动态化。 我是jquery的新手我发现它非常有用但老实说我不知道如何正确地实现它,特别是在事件上。 谢谢你提前。