我在页面中有五个文本字段,当用户在第一个文本字段中输入某些内容时,我需要根据第一个文本字段检索值。现在,我已经将数值硬编码为121,它正在从DB正确返回值,但是如何使其变为动态?在用户输入时检索数据
<?php echo $form->textField(emp::model()->findByAttributes(array('id' => '121')),'empno'); ?>
我在页面中有五个文本字段,当用户在第一个文本字段中输入某些内容时,我需要根据第一个文本字段检索值。现在,我已经将数值硬编码为121,它正在从DB正确返回值,但是如何使其变为动态?在用户输入时检索数据
<?php echo $form->textField(emp::model()->findByAttributes(array('id' => '121')),'empno'); ?>
可以AJAX调用它,而在文本框中键入如下:
$("textbox").on('keyup',function(){
// use get or post request here to retrieve the data
$.post('url',{parameters},function(data){
//code to set the data in you UI
}
});
这不会自行工作。 – rtfm
使用Yii中的内置自动完成构件为。它基于jQuery UI库。
http://www.yiiframework.com/doc/api/1.1/CJuiAutoComplete
$this->widget('zii.widgets.jui.CJuiAutoComplete',array(
'name'=>'city',
'sourceUrl'=> "<your keyword suggestion url here>",
// additional javascript options for the autocomplete plugin
'options'=>array(
'minLength'=>'2',
),
));
Javascript成为> AJAX – rtfm
使用jQuery和Ajax。 – Rahul
请看这个https://stackoverflow.com/questions/14042193/how-to-trigger-an-event-in-input-text-after-i-stop-typing-writing –