jquery 当另一个输入框被更改时,启用下一个输入框的最佳方法是什么

wrrgggsh  于 12个月前  发布在  jQuery
关注(0)|答案(1)|浏览(200)

我有类似的东西:

<input id="1" type="text"></input>
<input id="2" type="text" disabled></input>

当我更改id=“1”的内容时,我想启用id=“2”。我可以让它以这种格式工作,但是,我需要它在一个特定的函数中,而不是一个通用的输入onchange事件,因为这个页面有很多输入:

$(document).ready(function(){
 $("input").change(function(){
  $(this).next().prop("disabled", false); // Element(s) are now enabled.
 });
});

我相信我的问题是传递“这个”信息以便能够改变下一个元素。我已经尝试了下面的代码行,但无法让他们工作。忽略我放在那里的警报,我只是想看看传递了什么信息。另外,我还传递了一个带有onchange事件的字符串。

$(el.id).next().prop("disabled", false);

function myFunction (str, el) {
 var newId = el.id;
 alert(newId);
 $(newId).next().prop("disabled", false);
}

function myFunction (str, id) {
 $(id).next().prop("disabled", false);
}

更新代码:

function Update(str, el){
  var xmlhttp=new XMLHttpRequest();
  xmlhttp.onreadystatechange=function()
     {
      if (xmlhttp.readyState==4) {
        if (xmlhttp.status==200) {
                    var newId = el.id;
                    alert(newId);
                    $(newId).next().prop("disabled", false);
        }
        else {

        }
      }
     };
    var Info = str;
    var queryString = Info;
    xmlhttp.open("POST","Reduced.php",true);
    xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlhttp.send(queryString);
    }
dxxyhpgq

dxxyhpgq1#

使用keyup事件侦听器。

$(document).ready(function(){
 $("input[type=text]").keyup(function(){
  $(this).next().prop("disabled", false); // Element(s) are now enabled.
 });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text">
<input type="text" disabled>
<input type="text" disabled>
<input type="text" disabled>
<input type="text" disabled>

相关问题