JavaScript如何获取被选中的a标签的值
来源:互联网 发布:宣传片制作 知乎 编辑:程序博客网 时间:2024/06/02 00:51
JavaScript难点解答:要获得指定的a标签的值,我们首先要用JavaScript找到这个a标签,这是一个难点,如何获取被选中的A标签的值,通过下面这种方法,我们就可以获得a标签的href的值,还可以获得a标签的innerHTML,这里我们使用的是原生的JavaScript代码,没有框架。
第一部分:JavaScript代码
//获取被选中的a标签的值
function getUrl(e) {
e = e || event;
var target = e.target || e.srcElement,
href;
if (target.tagName === 'A') {
href = target.href;
alert(href);
}
}
第二部分:html代码
这种获取选中标签的方式,是通过监听body来实现的,所以body上要增加这个onclick事件
<body onclick="getUrl(arguments[0])">
第三部分:html代码
<div id="container">
<table class="zebra">
<thead>
<tr>
<th><a href="javascript:void(0)" onclick="gotoFirstPage();">首</a></th>
<th>上</th>
<c:forEach items="${total_pages}" var="item" begin="0" end="9">
<input type="hidden" id="current_Page" value="${item}"/>
<!-- 获取这个a标签的href中的值,由于有N多个a标签,并且ID相同,没有办法根据id来获取 -->
<th><a href="<%=basePath%>mysqlQueryPage.action?current_page=${item}" onclick="getUrl(e);return false;">${item}</a></th>
</c:forEach>
<th>下</th>
<th>尾</th>
<th>到第XXX页</th>
</tr>
</thead>
</table>
</div>
效果图:
- JavaScript如何获取被选中的a标签的值
- JSP中如何获取select标签选中的值
- JavaScript和jQuery如何判断select是否被选中并获取select选中的值
- js获取select标签选中的值
- jquery获取radio标签选中的值
- js获取select标签选中的值
- js获取select标签选中的值
- JS获取select标签选中的值
- js获取select标签选中的值
- js获取select标签选中的值
- js获取select标签选中的值
- js获取select标签选中的值
- js获取select标签选中的值
- js获取select标签选中的值
- js获取select标签选中的值
- JS获取Select标签选中的值
- js获取select标签选中的值
- js获取select标签选中的值
- netty服务器搭建-http
- 北斗七星
- 网络编程学习笔记一:Socket编程
- c#一维条码生成图片
- lua在stm32上的移植
- JavaScript如何获取被选中的a标签的值
- 开篇留记
- Spring 任务调度配置及使用
- Android开发BUG集锦
- 性能测试--如何设定定时开始性能测试
- 好用的xcode插件
- html乱码原因与网页乱码解决方法
- 全球最佳CRM排名:Salesforce与Zoho继续领跑
- JQuery的animate中callback函数的使用