Yii CJuiAutoComplete 默认显示值并在单击时清除它
我有下面的 CJuiAutoComplete ,加载时我想在文本字段中显示“搜索”,然后单击我想清除。我尝试在选项下使用“值”,但无法使其工作。感谢您的帮助,
还尝试了
'htmlOptions'=>array('value'=>'Search',)
<?php
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'name'=>'test1',
'source'=>'js: function(request, response) {
$.ajax({
url: "'.$this->createUrl('myAutoComplete/autoCompleate').'",
dataType: "json",
data: {
term: request.term,
brand: $("#type").val()
},
success: function (data) {
response(data);
}
})
}',
'options' => array(
'showAnim' => 'fold',
'select' => 'js:function(event, ui){ alert(ui.item.value) }',
'click'=>'js:function( event, ui ) {
alert("test");
return false;
}',
),
'htmlOptions'=>array('value'=>'Search',)
));
?>
问候
UPDATE
直接输入 'value' =>'搜索成功了。
检查点击处理程序
Kiran
I have below CJuiAutoComplete and when loading I want to display "Search" in the text field and on click I want to clear . I tried using "value" under options , but couldn't make it work . Thanks for your help
tried also
'htmlOptions'=>array('value'=>'Search',)
<?php
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'name'=>'test1',
'source'=>'js: function(request, response) {
$.ajax({
url: "'.$this->createUrl('myAutoComplete/autoCompleate').'",
dataType: "json",
data: {
term: request.term,
brand: $("#type").val()
},
success: function (data) {
response(data);
}
})
}',
'options' => array(
'showAnim' => 'fold',
'select' => 'js:function(event, ui){ alert(ui.item.value) }',
'click'=>'js:function( event, ui ) {
alert("test");
return false;
}',
),
'htmlOptions'=>array('value'=>'Search',)
));
?>
Regards
UPDATE
directly putting 'value' =>'Search' worked .
Checking for click handler
Kiran
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以做的是为您的小部件提供一个 id,然后将
onClick
事件放置在小部件的htmlOptions
中,并使用 JavaScript 清除该值。您不能将
onClick
放在options
属性中,因为这些是 CJuiAutocomplete,onClick
未在 JUI 自动完成选项。干杯
What you can do is give your widget an id and then you place the
onClick
event in the widget'shtmlOptions
and using JavaScript you clear the value.You cannot put
onClick
in theoptions
attribute as these are jQuery options for the CJuiAutocomplete,onClick
is not defined in the JUI Autocomplete options.Cheers
老线程,但对于来到这里的新手来说,在 Yii CAutoComplete 中添加 html placeholder 属性很简单。请参阅下面的代码并添加到 htmloptions 行中:
Old thread, but for newbies who land up here, its simple to add a html placeholder attribute in Yii CAutoComplete. See code below and add in the htmloptions line: