企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
js如何获取点击标签里的键值和文字值: ``` <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>js如何获取点击标签里的键值和文字值</title> <script src="https://code.jquery.com/jquery-3.5.1.js" integrity="sha256-QWo7LDvxbWT2tbbQ97B53yJnYU3WhH/C8ycbRAkjPDc=" crossorigin="anonymous"></script> </head> <body> <div id="ok"></div> <ul id="test"> <li class="reserve1" value="val1">Glen</li> <li class="reserve2" value="val2">Tane</li> <li class="reserve3" value="val3">John</li> <li class="reserve4" value="val4">Ralph</li> </ul> <script> window.onload = function() { var obj_lis = document.getElementById("test").getElementsByTagName("li"); for(i=0;i<obj_lis.length;i++){ obj_lis[i].onclick = function() { var val = $(this).attr("value"); document.getElementById("ok").innerHTML = val + ' | ' + this.innerHTML; } } } </script> </body> </html> ```