Disable a textarea field with name attribute using jquery
This question already has an answer here:
Use attribute-value selector
To disable a textarea
$('textarea[name="example"]').prop('disabled', true); // disable
To enable
$('textarea[name="example"]').prop('disabled', false); // enable
Demo
$('#myButton').on('click', function() {
var currentState = $(this).text();
$('textarea[name="example"]').prop('disabled', currentState === 'Disable');
$(this).text(currentState === 'Enable' ? 'Disable' : 'Enable');
});
button {
display: block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<textarea name='example' disabled>I want to diable this</textarea>
<button id="myButton">Enable</button>
Use $("#textbox1").attr("disabled", "disabled");
to disable your text box.
Demo
HTML
<span id="radiobutt">
<input type="radio" name="rad1" value="1" />
<input type="radio" name="rad1" value="2" />
<input type="radio" name="rad1" value="3" />
</span>
<div>
<input type="text" id="textbox1" />
<input type="checkbox" id="checkbox1" />
</div>
Javascript
$("#radiobutt input[type=radio]").each(function(i){
$(this).click(function () {
if(i==2) { //3rd radiobutton
$("#textbox1").attr("disabled", "disabled");
$("#checkbox1").attr("disabled", "disabled");
}
else {
$("#textbox1").removeAttr("disabled");
$("#checkbox1").removeAttr("disabled");
}
});
});
you should use the .prop() function with attribute-value selector
$('textarea[name="example"]').prop('disabled', true);
//$('textarea[name="example"]').prop('disabled', false);
Note: For jQuery 1.6+
or
$('textarea[name="example"]').attr("disabled","disabled");
链接地址: http://www.djcxy.com/p/23000.html
上一篇: 通过删除属性来启用和禁用按钮