javascript 常用代碼大全(六)

來源:互聯網
上載者:User

 

// 10

   JS 中,一些東西停用三種展現方式。 
我們在WEB項目中,有時候需要在使用者點擊某個東西的時候,一些東西不可用。如果在用戶端實現。最簡單的就是利用disabled 。下面羅列的其中三種方式:依次是:不可用(disabled);用一個空白來代替這個地方(Blank);這個地區為空白(None)。具體可以查看這個Blog的源檔案: 
obj.disabled = false; 
obj.style.visibility = "hidden"; 
obj.style.display = "none"; 

<SCRIPT language=javascript> 
function ShowDisableObject(obj) 

 if(obj.disabled == false) 
 { 
  obj.disabled = true; 
 } 
 else{ 
  obj.disabled = false; 
 } 
 var coll = obj.all.tags("INPUT"); 
 if (coll!=null) 
 { 
  for (var i=0; i<coll.length; i++) 
  { 
   coll[i].disabled = obj.disabled; 
  } 
 } 

function ShowBlankObject(obj) 

 if(obj.style.visibility == "hidden") 
 { 
  obj.style.visibility = "visible"; 
 } 
 else 
 { 
  obj.style.visibility = "hidden"; 
 } 

function ShowNoneObject(obj) 

 if(obj.style.display == "none") 
 { 
  obj.style.display = "block"; 
 } 
 else 
 { 
  obj.style.display = "none"; 
 } 

</SCRIPT> 
<P></P> 
<DIV id=Show01>dadd 
<DIV>ccc</DIV><INPUT> <INPUT type=checkbox> </DIV> 
<P><INPUT onclick=ShowDisableObject(Show01); type=button value=Disable> <INPUT id=Button1 onclick=ShowBlankObject(Show01); type=button value=Blank name=Button1> <INPUT id=Button2 onclick=ShowNoneObject(Show01); type=button value=None name=Button2> </P><!--示範代碼結束//--> 

On this page I explain a simple DHTML example script that features invisibility,
moving and the changing of text colour. 

Example 
Test TextMake test text invisible. 
Make test text visible. 
Move test text 50 pixels down. 
Move test text 50 pixels up. 
Change colour to red. 
Change colour to blue. 
Change colour to black. 
Change the font style to italic. 
Change the font style to normal. 
Change the font family to ’Times’. 
Change the font family to ’Arial’. 

The script 
The scripts work on this HTML element: 
<DIV ID="text">Test Text</DIV> 
#text {position: absolute; 
top: 400px; 
left: 400px; 
font: 18px arial; 
font-weight: 700; 

These scripts are necessary for the three effects: 
var DHTML = (document.getElementById || document.all || document.layers); 
function getObj(name) 

  if (document.getElementById) 
  { 
  this.obj = document.getElementById(name); 
this.style = document.getElementById(name).style; 
  } 
  else if (document.all) 
  { 
this.obj = document.all[name]; 
this.style = document.all[name].style; 
  } 
  else if (document.layers) 
  { 
   this.obj = document.layers[name]; 
   this.style = document.layers[name]; 
  } 

function invi(flag) 

if (!DHTML) return; 
var x = new getObj(’text’); 
x.style.visibility = (flag) ? ’hidden’ : ’visible’ 

var texttop = 400; 
function move(amount) 

if (!DHTML) return; 
var x = new getObj(’text’); 
texttop += amount; 
x.style.top = texttop; 

function changeCol(col) 

if (!DHTML) return; 
var x = new getObj(’text’); 
x.style.color = col; 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.