【发布时间】:2016-01-20 16:03:50
【问题描述】:
这是我的表格:
<div class="mutiple-array-form">
<?php $form = ActiveForm::begin(); ?>
<table id="sampleTbl", class="table table-striped table-bordered">
<thead>
<tr id="myRow">
<th>Name</th>
<th>Age</th>
</tr>
</thead>
<tbody>
<tr>
<td>william</td>
<td>32</td>
</tr>
<tr>
<td>Muli</td>
<td>25</td>
</tr>
<tr>
<td>Sukoco</td>
<td>29</td>
</tr>
</tbody>
</table>
<div class="form-group">
<?= Html::button('Create',['class' => 'btn btn-success _addNew', 'onclick' => 'myfunction()']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
以下是我的 Javascript 代码:
<?php
$script = <<< JS
function myfunction() {
alert(document.getElementById("sampleTbl").rows.namedItem("myRow").innerHTML);
}
JS;
$this->registerJs($script);
?>
我的代码不起作用。当我单击按钮时,没有任何反应。例如,我想在警报中使用数组显示表值。请帮忙!
【问题讨论】:
-
你检查了你的渲染文件,其中添加了你的 js 文件。这是正确的地方吗
标签: javascript php arrays yii2