Prototype实战教程 13.Form.Element.Observer

<script src="prototype.js"></script>
<form id="frm">
<div id="div1">
  <input type="text" id="txt" name="txt" onchange="return alert('Now')"/>
  <input type="text" id="txt2" name="txt2" />
  <input type="button" id="btn" name="btn"
    value="click" onclick="test(event)" />
  <input type="submit" />
  <a href="" onclick="test2(event)">Google</a>
  <input type="button" id="btn1" name="btn1"
  value="click" onclick="test3(event)" />
</div>
</form>
<script>
function test(evt) {
  alert($("btn") === Event.element(evt));
}

function test2(evt) {
  alert("clicked");
  Event.stop(evt);
}

function test3(evt) {
  alert($("div1") === Event.findElement(evt, "div"))
}

new Form.EventObserver("frm", function () {
    alert("form changed");
  }
);

new Form.Element.EventObserver("txt", function () {
    alert("txt changed");
  }
);

new Form.Observer("frm", 1, function () {
    alert("form changed");
  }
);

new Form.Element.Observer("txt", 1, function () {
    alert("changed");
  }
);
</script>

时间: 2024-10-31 11:09:44

Prototype实战教程 13.Form.Element.Observer的相关文章

Prototype实战教程 10.Element

<html><head><script src="prototype.js"></script> <script> function testRemove() { Element.remove("mydiv3"); } function testReplace() { Element.replace("myDiv2",'<img src="200607061129268f

Prototype实战教程 7.AJAX

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Ajax</title> <script type="text/javascript" langu

Prototype实战教程 5.$R

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>$R</title> <script type="text/javascript" languag

Prototype实战教程 4.$H

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>$H</title> <script type="text/javascript" languag

Prototype实战教程 3.$F

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""> <html> <head> <title>$F</title> <script type="text/javascript" language="javascript" src="prototype.js" &

Prototype实战教程 2.$A

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""> <html> <head> <title>$A</title> <script language="javascript" src="prototype.js" type="text/javascript"&g

Prototype实战教程 8.顶层对象

<html> <head> <title>顶层元素</title> <script src="prototype.js"></script> <script> var Person=Class.create(); Person.prototype={ initialize:function(){}, name:'', birthday:'', age:'', Show:function(){alert(

Prototype实战教程 6.$

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""> <html> <head> <title>$</title> <script type="text/javascript" language="javascript" src="prototype.js" &g

Prototype实战教程 1.$$

<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