- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
您好,我正在使用 codeigniter 框架。当我单击一个按钮时,我有一个 javascript 来动态创建一个表行。我需要在动态添加的表格单元格内有一个下拉菜单。这是我到目前为止尝试过的代码。
function displayResult() {
<?php
$attributes = array('class' => 'form-horizontal', 'id' => '');
$options_employee = array('' => "Select");
foreach ($employee as $row)
{
$options_employee[$row['first_name']] = $row['first_name'];
}
?>
var something='<?php echo form_dropdown('employee', $options_employee, set_value('employee[]'), 'class="span2"');?>';
alert(something);
var row = document.getElementById("test").insertRow(-1);
row.innerHTML = '<td><div>'+something+'</div></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>';
}
单击按钮时,我调用此 displayResult()
。我的控制台出现 2 个错误。
1.Uncaught SyntaxError: Unexpected token ILLEGAL
2.Uncaught ReferenceError: displayResult is not defined
有人可以帮助我吗?请帮我修复这段代码。
function displayResult() { <? php
$attributes = array('class' => 'form-horizontal', 'id' => '');
$options_employee = array('' => "Select");
foreach($employee as $row) {
$options_employee[$row['first_name']] = $row['first_name'];
}
?>
var something = '<?php echo form_dropdown('
employee ', $options_employee, set_value('
employee[]
'), '
class = "span2"
');?>';
alert(something);
var row = document.getElementById("test").insertRow(-1);
row.innerHTML = '<td><div>' + something + '</div></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>';
}
<div id="form">
<!-- div form starts here.its for add table -->
<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 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>
最佳答案
这对我来说很好用。谢谢大家的支持!!
function displayResult() {
<?php
$attributes = array('class' => 'form-horizontal', 'id' => '');
$options_employee = array('' => "Select");
foreach ($employee as $row)
{
$options_employee[$row['first_name']] = $row['first_name'];
}
$dropdown = form_dropdown('employee', $options_employee, set_value('employee[]'), 'class="span2"');
?>
var complex = <?php echo json_encode($dropdown); ?>;
var row = document.getElementById("test").insertRow(-1);
row.innerHTML =
'<td><div>'+complex+'</div></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>';
}
关于javascript - 我可以在 javascript 中使用 form_dropdown 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32687376/
我在 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
我是一名优秀的程序员,十分优秀!