WEB开发网
开发学院网页设计JavaScript Prototype实战教程----1.$$ 阅读

Prototype实战教程----1.$$

 2010-09-14 13:10:36 来源:WEB开发网   
核心提示:<html><head><title>Test $$</title><script src="prototype.js"></script><script>function test$$(){/**//*in cas

<html>
<head>
<title>Test $$</title>
<script src="prototype.js"></script>
<script>
function test$$(){
  /**//*
   in case CSS is not your forte, the expression below says
   'find all the INPUT elements that are inside
   elements with class=field that are inside a DIV
   with id equal to loginForm.'
  */
  var f = $$('div#loginForm .field input');
  var s = '';
  for(var i=0; i<f.length; i++){
    s += f[i].value + '/';
  }
  alert(s); // shows: "joedoe1/secret/"
  //now passing more than one expression
  f = $$('div#loginForm .field input', 'div#loginForm .fieldName');
  s = '';
  for(var i=0; i<f.length; i++){
    s += ( f[i].value ? f[i].value : f[i].innerHTML ) + '/';
  }
  alert(s); //shows: "joedoe1/secret/User name:/Password:/"
var  temp=$$('div#loginForm .field');
  alert(temp.innerHTML);
}
function testtoColorPart()
{var num=new Number(50);
  alert(num.toColorPart());
  }

</script>

<div id='loginForm'>
  <div class='field'>
    <span class='fieldName'>User name:</span>
    <input type='text' id='txtName' value='joedoe1'/>
  </div>
  <div class='field'>
    <span class='fieldName'>Password:</span>
    <input type='password' id='txtPass' value='secret' />
  </div>
  <input type='submit' value='login' />
</div>
<input type=button value='test $$()' onclick='test$$();' />
<input type=button value='testtoColorPart' onclick='testtoColorPart();' />
</body>
</html>

Tags:Prototype 实战 教程

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接