【发布时间】:2020-10-29 15:40:19
【问题描述】:
我有类似的东西:
<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);
}
【问题讨论】:
标签: javascript jquery next attr prop