我在 yii 中使用 java 脚本函数 _form 视图 在这个函数中,我将值存储在变量中,我想在 yii 文本字段中访问这些变量
所以请告诉我如何在 Yii 中从 JavaScript 变量访问文本字段输入这是我的 javascript 函数,我尝试这个,但它向我显示空白结果
<script language="javascript">
function get_data(element)
{
var te_id = $(element).val();
document.getElementById('data').value=te_id;
}
</script>
<?php echo $form->TextField($model,'data',array('value'=>'')); ?>
您的代码显示您希望在初始化后访问这些值,因此您应该添加 html 选项:
<?php echo $form->TextField($model,'data',array('onclick'=>'get_data(this)')); ?>
一个使用你的get_data函数。
或为其分配 ID
<?php echo $form->TextField($model,'data',array('id'=>'myInput')); ?>
,然后使用按钮进行更改:
<script>
$(document).ready(function(){
$('#someButton').click(function(){ // change the value on some button click
var inputValue = $('#myInput').val();
//now assign it to ther place
$('#otherInput').val(inputValue);
});
});