[英]Get input text value inside td with javascript
我通過使用CGridView創建了一個表,該表內部包含允許用戶插入值的輸入文本字段。 問題是我可以從沒有輸入字段的表中獲取文本,但不能從包含輸入字段的表中獲取文本。
Php:
<?php
$this->widget('zii.widgets.grid.CGridView',array(
'id' => 'oc-list-upgradeRule',
'dataProvider' => $upgradeRuleDataProvider,
'selectableRows' => 2,
'summaryText' => '',
'columns' => array(
array(
'header' => '',
'id' => 'chkbox',
'name' => 'checkBox',
'class' => 'CCheckBoxColumn',
),
array(
'header' => 'Min. Spending Amount',
'id' => 'minSpendingAmount',
'name' => 'minSpendingAmount',
'type' => 'raw',
'value' => 'CHTML::textField("",$data["minSpendingAmount"],array())',
'htmlOptions'=>array(
'style'=>'text-align: center;'
)
)
)
));
?>
Javascript:
$(document).on('change', 'input', function () {
var upgradeRenewDowngrade = $('.oc-upgrade-renew-downgrade');
upgradeRenewDowngrade.find('.oc-save-upgrade-downgrade-rules').click(function (e) {
var sel = $.fn.yiiGridView.getChecked('oc-list-upgradeRule', 'chkbox');
var row = $.fn.yiiGridView.getRow('oc-list-upgradeRule', sel);
var minSpendAmount = row.get(5);
var input = $(minSpendAmount).html();
//console.log($(input).val());
console.log(minSpendAmount);
})
})
從上面的代碼中,我只能將td與輸入文本字段一起獲取。
<td style="text-align: center;">
<input type="text" value="365" name id>
</td>
如何獲得輸入的文字值? 您可能建議使用其他方法從CGridView獲取值。 謝謝。
好吧...
玩了一點您的代碼,我最終得到了這一點:
// Here, I only set my variable to be the same as yours var minSpendAmount = '<td style="text-align: center;"> <input type="text" value="365" name id></td>'; // Code you may do instead of your current console.log(minSpendAmount) var input = $(minSpendAmount).html(); console.log($(input).val());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
告訴我是否有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.