给html元素的onclick事件传递参数(即如何获取html标签的data-*属性&直接传参方法)

DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>title>
         <script src="js/jquery/jquery.min.js">script>
         <script>
             $(document).ready(function(){
                 $(".title").click(function(){
                     var id=$(this).data("id");
                     var name=$(this).data("name");
                     alert("Id: "+id+" ; Name: "+name);});
             });
             
             function onClick(e){
                 var id=e.getAttribute("data-id");
                var name=e.getAttribute("data-name");
                 alert("Id: "+id+" ; Name: "+name);
             }
         script>
    head>
    <body>
        <div class="title" data-id="1" data-name="Microsoft">Click Mediv>
        <div id="add" data-id="2" data-name="Google" onclick="onClick(this)">Click Mediv>
    body>
html>
 
  

<script>

function UClicked(string) {

window.webkit.messageHandlers.MHName.postMessage({body: string});}

script>

<body>

<input type="button" onclick="UClicked("String")" />

body>


你可能感兴趣的:(html,iOS,前端开发,iOS)