<html>
<head>
<title>Problema</title>
<script type="text/javascript" src="../jquery.js"></script>
<script type="text/javascript" src="funciones.js"></script>
</head>
<body>
<form action="#" method="post">
<input type="text" name="buscar" id="buscar"
value="Buscar..." size="20">
</form>
</body>
</html>
funciones.js
var x;
x=$(document);
x.ready(inicializarEventos);
function inicializarEventos() {
var x;
x=$("#buscar");
x.focus(tomaFoco); }
function tomaFoco() {
var x=$("#buscar");
x.attr("value",""); }
En la función inicializarEventos creamos un objeto jQuery a partir del id del control de tipo text y asociamos el evento focus con el método tomaFoco:
x=$("#buscar");
x.focus(tomaFoco);
El método tomaFoco obtiene la referencia del elemento tipo text y mediante el método attr modifica la propiedad value:
function tomaFoco() {
var x=$("#buscar");
x.attr("value",""); } |