首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >基于其他TextField Jquery启用TextField

基于其他TextField Jquery启用TextField
EN

Stack Overflow用户
提问于 2013-08-05 09:21:52
回答 2查看 118关注 0票数 1

有两个文本字段(具有自动完成功能):

代码语言:javascript
复制
<label for="name">Customer:</label>
<input type="text" name="customer" id="customer" value=""  />
<input type="hidden" id="customer-id" />
<p id="customer-description"></p>


<label for="name">Store:</label>
<input type="text" name="store" id="store" value=""  disabled="true" />
<input type="hidden" id="store-id" />
<p id="store-description"></p>

如您所见,最初我禁用了第二个textfield。我想要的是当用户完成从customer中选择项目时,应该启用商店textbox。这是我尝试过的,但它没有启用存储字段:

代码语言:javascript
复制
$(function() {
    $('#customer').autocomplete({
        source: "./SearchCustomer.php?term="+document.getElementById("customer").value,
        minLength: 0,
        focus: function( event, ui ) {
            $( "#customer" ).val( ui.item.label );
            return false;
        },
        select: function (event, ui) {
            $( "#customer" ).val( ui.item.label );
            $( "#customer-id" ).val( ui.item.value );
            return false;
        }
    })
    .data( "ui-autocomplete" )._renderItem = function( ul, item ) {
      return $( "<li>" ).append( "<a>" + item.label + "</a>" ).appendTo( ul );
    };
    $("#store").removeAttr("disabled").focus();
});

你的帮助将不胜感激。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-08-05 09:29:39

尝尝这个

代码语言:javascript
复制
$(function() {
    $('#customer').autocomplete({
        source: "./SearchCustomer.php?term="+document.getElementById("customer").value,
        minLength: 0,
        focus: function( event, ui ) {
            $( "#customer" ).val( ui.item.label );
            return false;
        },
        select: function (event, ui) {
            $( "#customer" ).val( ui.item.label );
            $( "#customer-id" ).val( ui.item.value );
            $("#store").removeAttr("disabled").focus();
            return false;
        }
    })
    .data( "ui-autocomplete" )._renderItem = function( ul, item ) {
      return $( "<li>" ).append( "<a>" + item.label + "</a>" ).appendTo( ul );
    };

});
票数 1
EN

Stack Overflow用户

发布于 2013-08-05 09:30:40

$('#store').prop('disabled', false).focus();添加到选择函数中:

代码语言:javascript
复制
select: function(ev, ui) {
    $( "#customer" ).val( ui.item.label );
    $( "#customer-id" ).val( ui.item.value );
    $( "#store" ).prop( 'disabled', false ).focus();
    return false;
}

因此,当选择一个自动完成项时,将#store的禁用属性设置为false,并给出元素焦点。

这里有把小提琴

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18054618

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档