type1. jquery
Disable All Form Elements
Another question I have seen a lot lately is how can I disable all of the form elements on the page with JavaScript? Well it is rather simple and only takes a few lines of code. All you need to do is loop through the Form elemnt array and set the disabled property to true to disable the elements and false to enable the elements.
function DisableEnableForm(xForm,xHow){ objElems = xForm.elements; for(i=0;i<objElems.length;i++){ objElems[i].disabled = xHow; } }To execute the function, you just need to send the form object reference and a boolean value to the function. The following code is an example how to call the function disable the elements as the page is loading.
window.onload= function(){ DisableEnableForm(document.Form1,true);}
---------------------------------------------------------------------------------------------------
type2. script
- <script>
- function go(){
- if(document.getElementById("chk").checked){
- document.getElementById("but").disabled = false;
- document.getElementById("tex").disabled = false;
- }else{
- document.getElementById("but").disabled = true;
- document.getElementById("tex").disabled = true;
- document.getElementById("tex").value="";
- }
- }
- </script>
---------------------------------------------------------------------------------------------------
type3. jquery
src
=
"http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"
></
script
>
02.
<
script
type
=
"text/javascript"
>
03.
$(document).ready(function () {
04.
$('#sameAsShipping').change(function () {
05.
if (this.checked) {
06.
$('#billingInfo input:text').attr('disabled', 'disabled')
07.
.each(function (i) {
08.
var valueFromShippingInput = $('#shippingInfo input:text:eq(' + i + ')').val();
09.
$(this).val(valueFromShippingInput);
10.
});
11.
12.
} else {
13.
$('#billingInfo input:text').removeAttr('disabled');
14.
}
15.
}).trigger('change');
16.
});
17.
</
script
>
'마니의 공부방 > 개발 꼼수' 카테고리의 다른 글
구글 크롬 단축키 (0) | 2011.03.17 |
---|---|
두개의 도메인 + 하나의 아파치 + 각각 도메인별 두개의 톰켓 (1) | 2011.03.16 |
[excel] 한영 자동변환 기능 끄기 (0) | 2011.03.16 |
[jsp] 파라미터 한글깨짐현상 (0) | 2011.03.10 |
[jsp] jsp 로 엑셀 excel 다운로드 파일 만들기 (한글깨짐, 숫자 포함) (0) | 2011.03.02 |