選中事件,當文本框或者文本域中的文字被選中時,觸發onselect事件,同時調用的程序就會被執行。
如下代碼,當選中用戶文本框内的文字時,觸發onselect 事件,並調用函數message()。
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>onselect</title>
<script type="text/javascript">
function message(){
alert("您觸發了事件!");
}
</script>
</head>
<body>
<form>
用戶:<input name="username" type="text" value="請輸入用戶名!" onselect="message()" />
<!--當選中用戶文本框内的文字時,觸發onselect事件。-->
</form>
</body>
</html>