- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
您好,我正在使用 codeigniter。我需要在 javascript 中嵌入一个 form_dropdown
。我有一个带有按钮添加行的表。当我点击添加时,我复制了上面的同一行。在我的 View 页面中,我有一个 javascript 来添加动态表行。现在我无法在其中添加下拉菜单。我有一个 Controller 文件,我在其中传递应显示为下拉框的数据。我的 Controller 功能:
class Admin_billing extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('billing_model');
if(!$this->session->userdata('is_logged_in')){
redirect('admin/login');
}
}
public function ticket($id)
{
$this->load->library('session');
$this->session->unset_userdata('client_detail');
$id=$this->uri->segment(4);
$data['id']=$this->uri->segment(4);
$data['employee']=$this->billing_model->emp_name();
$data['main_content'] = 'admin/billing/ticket_page';
$this->load->view('includes/template', $data);
}
}
我的模型函数:
<?php
class billing_model extends CI_Model {
public function __construct()
{
$this->load->database();
}
public function emp_name()
{
$this->db->select('employee.first_name');
$this->db->from('employee');
$this->db->group_by('employee.id');
$query = $this->db->get();
return $query->result_array();
}
}
?>
这里我有一个 emp_name 函数来从我的数据库中获取员工姓名。我的查看页面:
<script>
function displayResult() {
var row = document.getElementById("test").insertRow(-1);
row.innerHTML = '<td>form_dropdown('employee', $options_employee, set_value('employee[]'), 'class="span2"')</td><td><input type="text" name="start_time[]" value="" style="width:35px;"/></td><td><input type="text" name="pid[]" style="width:35px;"/></td><td><input type="text" name="description[]" class="description" value="" style="width:145px;"/></td><td><input type="text" class="type" value="" style="width:45px;"/></td><td><input type="text" class="qty_prch" value="" style="width:45px;"/></td><td><input type="text" class="qty_used" value="" style="width:45px;"/></td><td><input type="text" value="" style="width:70px;"/></td><td><input type="text" value="" style="width:70px;"/></td><td><input type="text" value="" style="width:70px;"/></td><td><input type="text" value="" style="width:70px;"/></td>';
}
</script>
<?php
$attributes = array('class' => 'form-horizontal', 'id' => '');
$options_employee = array('' => "Select");
foreach ($employee as $row)
{
$options_employee[$row['name']] = $row['name'];
}
?>
<table id="test">
<thead>
<tr>
<td style="width:80px;">Employee</td>
<td style="width:35px;">Start time</td>
<td style="width:35px;">Id</td>
<td style="width:145px;">Description</td>
<td style="width:45px;">Type></td>
<td style="width:45px;">qty prch></td>
<td style="width:45px;">qty used</td>
<td style="width:70px;">Price</td>
<td style="width:70px;">discount></td>
<td style="width:70px;">Tax></td>
<td style="width:70px;">Total</td>
</tr>
</thead>
<tbody>
<tr>
<td><?php echo form_dropdown('employee', $options_employee, set_value('employee[]'), 'class="span2"');?></td>
<td><input type="text" name="start_time[]" value="" style="width:35px;"/></td>
<td><input type="text" name="pid[]" value="" style="width:35px;"/></td>
<td><input type="text" name="description[]" class="description" value="" style="width:145px;"/></td>
<td><input type="text" name="type[]" class="type" style="width:45px;"/></td>
<td><input type="text" name="qty_prch[]" class="qty_prch" style="width:45px;"/></td>
<td><input type="text" name="qty_used[]" class="qty_used" style="width:45px;"/></td>
<td><input type="text" name="price[]" class="price" style="width:70px;"/></td>
<td><input type="text" name="discount[]" class="discount" style="width:70px;"/></td>
<td><input type="text" name="tax[]" class="tax" style="width:70px;"/></td>
<td><input type="text" name="total[]" class="total" style="width:70px;"/></td>
</tr>
</tbody>
</table>
<div id="add_row">
<button onClick="displayResult()" class="add_r"></button>
</div>
这是我在上表中的查看页面 我的第一个字段是下拉 php 代码。这适用于我表中的静态行。当我使用 javascript 添加新行时,我无法获得下拉列表。如何处理这个问题?有人可以帮我编写代码吗?
最佳答案
首先,PHP 是服务器端语言。如果您仅在 javascript 中附加到 html 您的行,则不会执行 php。
为此您需要使用 ajax。 jQuery 解决方案:
$.ajax({
url: "DOMAIN/newRow",
})
.done(function(data) {
$('table#test tbody').append(data);
}
});
PHP(在您的管理计费 Controller 中)
我对cakePHP不是很熟悉,就这么简单。您需要编写返回生成的行 html 的函数。
public function newRow()
{
$options_employee = 'prepare this variable here';
$dropdown = form_dropdown('employee', $options_employee, set_value('employee[]'), 'class="span2"');
// Send data to browser (return is only for demonstration)
return '<tr><td>' . $dropdown . '</td><td><input type="text" name="start_time[]" value="" style="width:35px;"/></td><td><input type="text" name="pid[]" style="width:35px;"/></td><td><input type="text" name="description[]" class="description" value="" style="width:145px;"/></td><td><input type="text" class="type" value="" style="width:45px;"/></td><td><input type="text" class="qty_prch" value="" style="width:45px;"/></td><td><input type="text" class="qty_used" value="" style="width:45px;"/></td><td><input type="text" value="" style="width:70px;"/></td><td><input type="text" value="" style="width:70px;"/></td><td><input type="text" value="" style="width:70px;"/></td><td><input type="text" value="" style="width:70px;"/></td></tr>';
}
关于javascript - 我们可以在 javascript 中嵌入 form_dropdown 函数吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32664779/
我在 CodeIgniter 中的 form_dropdown 函数有一些问题......我的应用程序分为两部分,用户进入,输入表单并提交......一旦提交,管理员可以进入并编辑该人员表单然后将其保
I'm wondering if someone can help me out. I have a form_dropdown which is filled with options from t
我想知道是否有人可以帮助我。我有一个 form_dropdown,我正在用数据库中的选项填充它。我想在列表顶部添加一个默认的“请选择”值,但不知道如何在不将其添加到数据库的情况下执行此操作。 我的代码
是否有任何可能的方法在 CodeIgniter 的 form_dropdown 中添加 class 和 id 属性? 我试过 form_dropdown('name',$array,'class','
情况 我有一个编辑表单,用于在我的数据库中编辑公司。我使用连接表向公司添加类别。 我的 table : Companies --------- idcompanies companyname coun
我在更新/编辑菜单时无法显示所选项目 该项目未被选择。如何让它自动选择? 这是我的模型 public function master_kategorilapor(){ $this->d
我正在尝试弄清楚如何使用 codeIgniter 在我的下拉列表中添加一个禁用的选项。 CI 的新手,我尝试用谷歌搜索了一下,但找不到答案。 我的下拉代码如下所示: echo form_dro
我的表单中有一个下拉字段,当我点击提交时,表单会通过验证,如果发生错误,则返回所有值。这项工作需要我的下拉菜单,我在下拉菜单中有 set_value 但它不起作用 :( 这是我的代码 我做错了什么或
您好,我正在使用 codeigniter。我需要在 javascript 中嵌入一个 form_dropdown。我有一个带有按钮添加行的表。当我点击添加时,我复制了上面的同一行。在我的 View 页
您好,我正在使用 codeigniter 框架。当我单击一个按钮时,我有一个 javascript 来动态创建一个表行。我需要在动态添加的表格单元格内有一个下拉菜单。这是我到目前为止尝试过的代码。 f
我有一个带有类别下拉列表的表单。 看起来像这样: 对于 $opties 我使用这段代码: $dbres = $this->db->get('categorieen'); $dd
我尝试使用 javascript 提交没有提交按钮的表单,但不起作用。我的代码是: js 是: function submitform() { document.autosubmit.subm
我想在 CI 的博客模块中显示类别列表的下拉列表。 在博客表中: 我有 news_id、category_id、news_title、news_slug 在类别表中:我有类别 ID、类别名称、类别 s
我是一名优秀的程序员,十分优秀!