onclick 事件

1.只能在IE上显示

<!DOCTYPE html>
<html>
<head>
<title>标记应用</title>
<style type="text/css">
p{
text-align:center;
font-family:"黑体";
font-size:24px;

}
</style>
</head>
<body>
<p>html5页面</p>
<?php
$str1="PHP变量1";
$str2="PHP变量2";
echo"<script>";
echo"alert('".$str1."');";
echo"</script>";
?>
<input type="text"name="tx"size=20><br>
<input type="button"name="bt"value="单击"onclick="tx.value='<?php echo $str2;?>'">
</body>
</html>

2.可以同时兼容多个浏览器

<!DOCTYPE html>
<html>
<head>
<title>标记应用</title>
<style type="text/css">
p{
text-align:center;
font-family:"黑体";
font-size:24px;
 
}
</style>
</head>
<body>
<p>html5页面</p>
<?php
$str1="PHP变量1";
$str2="PHP变量2";
echo"<script>";
echo"alert('".$str1."');";
echo"</script>";
?>
<input type="text"name="tx" id="tx" size=20><br>
<input type="button"name="bt"value="单击"onclick="document.getElementById('tx').value='<?php echo $str2;?>'">
</body>
</html>

 http://bbs.csdn.net/topics/392076513

#################

refer:

定义和用法

onclick 事件会在对象被点击时发生。

请注意, onclick 与 onmousedown 不同。单击事件是在同一元素上发生了鼠标按下事件之后又发生了鼠标放开事件时才发生的。

语法

onclick="SomeJavaScriptCode"
参数描述
SomeJavaScriptCode 必需。规定该事件发生时执行的 JavaScript。

支持该事件的 HTML 标签:

<a>, <address>, <area>, <b>, <bdo>, <big>, <blockquote>, <body>, <button>, 
<caption>, <cite>, <code>, <dd>, <dfn>, <div>, <dl>, <dt>, <em>, <fieldset>, 
<form>, <h1> to <h6>, <hr>, <i>, <img>, <input>, <kbd>, <label>, <legend>, 
<li>, <map>, <object>, <ol>, <p>, <pre>, <samp>, <select>, <small>, <span>, 
<strong>, <sub>, <sup>, <table>, <tbody>, <td>, <textarea>, <tfoot>, <th>, 
<thead>, <tr>, <tt>, <ul>, <var>

支持该事件的 JavaScript 对象:

button, document, checkbox, link, radio, reset, submit

实例 1

在本例中,当按钮被单击时,第一个输入框中的文本会被拷贝到第二个输入框中:

<html>
<body>

Field1: <input type="text" id="field1" value="Hello World!">
<br />
Field2: <input type="text" id="field2">
<br /><br />
点击下面的按钮,把 Field1 的内容拷贝到 Field2 中:
<br />
<button onclick="document.getElementById('field2').value=
document.getElementById('field1').value">Copy Text</button>

</body>
</html>

输出:

Field1: 

Field2: 

点击下面的按钮,把 Field1 的内容拷贝到 Field2 中:

原文地址:https://www.cnblogs.com/feiyun8616/p/6322183.html