English 中文(简体)
选定 j子后的明确形式领域
原标题:Clear form field after select for jQuery UI Autocomplete

I m 开发一种形式,并使用j Query UI Autocomplete。 当用户选择一种选择时,我希望选择在括号后面的一段时期内插入<代码><p>。 然后,我想到这个领域是清楚的,而不是有人选择。

我的间隔似乎只是罚款,但我不能让实地清楚。

你们如何取消“团结倡议”的缺省选择行动?

我的守则是:

var availableTags = ["cheese", "milk", "dairy", "meat", "vegetables", "fruit", "grains"];
$("[id^=item-tag-]").autocomplete({
    source: availableTags,

    select: function(){
        var newTag = $(this).val();
        $(this).val("");
        $(this).parent().append("<span>" + newTag + "<a href="#">[x]</a> </span>");
    }
});

只是做以下工作:$(this.val("); don t work。 令人厌恶的是,如果我忽视汽车公司,那么几乎所有的确切功能都会被罚款,而且当用户对ma进行分类时,就采取行动:

$( [id^=item-tag-] ).keyup(function(e) {
    if(e.keyCode == 188) {
        var newTag = $(this).val().slice(0,-1);
        $(this).val(  );
        $(this).parent().append("<span>" + newTag + "<a href="#">[x]</a> </span>");
    }
});

真正最终的结果是,实现自动化,以进行多种选择。 如果有人对此提出任何建议,将表示欢迎。

最佳回答

Add $(this).val( ); return false; to the end of your select function to clear the field and cancel the event :)

这将防止价值得到更新。 http://github.com/jquery/jquery-ui/blob/master/ui/jquery.ui.autocomplete.js”rel=“noretinger”>。

《刑法》对伪造进行了具体检查:

if ( false !== self._trigger( "select", event, { item: item } ) ) {
  self.element.val( item.value );
}
问题回答

否则,你也可以使用假肢。

select: function(event, ui){
    var newTag = $(this).val();
    $(this).val("");
    $(this).parent().append("<span>" + newTag + "<a href="#">[x]</a> </span>");
    event.preventDefault();
}

return false is needed within the select callback, to empty the field. but if you want to again control the field, i.e. set the value, you have to call a new function to break out of the ui.

也许你具有迅速价值,例如:

var promptText = "Enter a grocery item here."

把它算作一个要素。 (关于我们确定的工作重点)。

$("selector").val(promptText).focus(function() { $(this).val(  ); }).autocomplete({
    source: availableTags,
    select: function(){
        $(this).parent().append("<span>" + ui.item.value + "<a href="#">[x]</a> </span>");
     foo.resetter(); // break out //
    return false;  //gives an empty input field // 
    }
});

foo.resetter = function() {
  $("selector").val(promptText);  //returns to original val
}

这对我来说是好的。

在选定活动之后, 我使用了事件变化。

 change:function(event){
   $("#selector").val("");  
   return false;
 }

我!

提 出 ......

select: function (event, ui) {
    $(this).val(  );
    return false;       
}

我刚刚解决了这一问题,不得不失去重点:

$( #select_id ).blur();
printResult();




相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签