• 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 中:

  • 相关阅读:
    SAS 数据集生成map 文件
    尝试打开或创建物理文件 REATE FILE 遇到操作系统错误 5(拒绝访问)
    sas编程-日期相差计算函数 intnx
    msqlserver 千万级别单表数据去掉重复记录使用临时表
    bootstrap下使用模态框,在模态框内输入框中回车时,模态框自动关闭的问题及解决方法
    .net 环境下get 获取页面出现乱码问题解决
    关于富文本编辑框与纯文本编辑框初始化加载过程的问题
    SVN版本问题:svn: E155021: This client is too old to work with the working copy at
    new一个对象时,会经历哪些步骤
    var、let、const区别
  • 原文地址:https://www.cnblogs.com/feiyun8616/p/6322183.html
Copyright © 2020-2023  润新知