Javascript 在另一个文本字段中键入内容时启用文本字段
我有这个密码Javascript 在另一个文本字段中键入内容时启用文本字段,javascript,jquery,html,Javascript,Jquery,Html,我有这个密码 <label for='password' >password </label><br/> <input type="password" name="password1" placeholder="Password" /><br /> <label for='password2' >repeat password</label><br/>
<label for='password' >password </label><br/>
<input type="password" name="password1" placeholder="Password" /><br />
<label for='password2' >repeat password</label><br/>
<input type="password" id="password2" name="password2" placeholder="Password (repeat)" disabled="true" /><br />
引导层:
HTML:
JS:
评论:
您没有输入[type=text],只有输入[type=password]因此,我认为您想禁用第二个输入…您忘记发布您尝试的JavaScript。好的,我将发布它now@Abeer别忘了接受答案以关闭帖子^^^或等待更好的答案我看到了你的新答案,所以这是对我来说最好的答案:pthanx再次提示LittlePigg我可以使用文本字段名而不是输入类型吗??密码2.last.prop'disabled',false;是:$'input[name=password2]'
$(document).ready(function() {
$('input[type="text"]').attr('disabled','disabled');
$('input[type="text"]').keyup(function() {
if($(this).val() != '') {
$('input[type="text"]').removeAttr('disabled');
}
});
});
<label for='password' >password </label><br/>
<input type="password" name="password1" placeholder="Password" /><br />
<label for='password2' >repeat password</label><br/>
<input type="password" id="password2" name="password2" placeholder="Password (repeat)" disabled="true" /><br />
$(document).ready(function() {
//$('input[type="text"]').prop('disabled',true); // <--- Stupid, to comment
$('input[type="password"]').keyup(function() {
if($(this).val() != '') {
$('input[type="password"]').last().prop('disabled', false);
} else {
$('input[type="password"]').last().prop('disabled', true);
}
});
});