setAttribute and getAttribute的用法 以及阻止<a>的href的默认属性

1,它们都有一个共同点那就是不能与document一起使用,因此我们可以利用对象的方式的来访问它,

for example

var pic=document.getElementById("id");

pic.getAttribute() || pic.setAttribute("value","new value");


2关于a链接的默认行为阻止;

for example

<a href="http://www.bibizan.cn" οnclick="return false;" >这是一个不能跳转的链接</a>

与disabled的区别就是这种方法,链接是可以点的动的,而disabled不能,点击的感觉有点像是空链接,但他是有链接的对象可惜被阻止了,


另一方面,a 的href属性就是就是他的预定义事件,而onclick也是它的事件,而他们的优先级是js代码段先执行,而href的预定义事件后执行;因此我们要给利用a标签但是又要改变它的默认链接时就可以使用它

for example

<a href="http://www.bibizan.cn" οnclick="function(); return false;" >因为这是两个代码块必要要用分号隔开,否则执行的是后者;之所以把return false写在后面就是因为a的href属性是在js代码段后执行的



setAttribute只能接受属性节点比如<p id="description" title=“one”>choose an picture </p>可以替换title的值,不能替换p段落内的文本,在此还需要注意的是p 是元素节点,而文本的内容属于文本节点,不是同类型的节点,需要用firstchild|| childNodes[0]

节点

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
给下面代码增加分页功能,要求细致,逻辑清楚,<form action="./../selectNews" method="post"> <input type="text" name="key" id="key" placeholder="请输入标题"/> <input type="submit" value="查询"/> <a href="zhuce.jsp">发布新闻</a> <a href="../user01/index.jsp">返回主页</a> </form> <table> <thead> <tr> <th>新闻编号</th> <th>新闻标题</th> <%-- <th>新闻内容</th>--%> <th>新闻类别</th> <th>发布人</th> <th>发布时间</th> <th>状态</th> <th>是否头条</th> <th colspan="4" align="center">操作</th> </tr> </thead> <tbody> <c:forEach items="${newslist}" var="u"> <tr> <td>${u.nid}</td> <td>${u.title}</td> <%-- <td>${u.content}</td>--%> <td>${u.type}</td> <td>${u.userName}</td> <td>${u.pubTime}</td> <td> <c:choose> <c:when test="${u.state==0}"><span style="color: ghostwhite">未审核</span></c:when> <c:when test="${u.state==1}"><span style="color: green">审核通过</span></c:when> <c:otherwise><span style="color: red">未通过</span></c:otherwise> </c:choose> </td> <td> <c:choose> <c:when test="${u.top==0}">否</c:when> <c:otherwise>是</c:otherwise> </c:choose> </td> <c:choose> <c:when test="${user.rule==1}"> <td> <a href="../NewsDetailServlet?nid=${u.nid}&op=show">查看</a> </td> <td> <a href="../NewsDetailServlet?nid=${u.nid}&op=update">修改</a> </td> <td> <a href="NewsDelete.jsp?nid=${u.nid}&title=${u.title}&userName=${user.userName}">删除</a> </td> <td> <a href="Newsshenhe.jsp?nid=${u.nid}&title=${u.title}&userName=${user.userName}">审核</a> </td> </c:when> <c:when test="${user.rule==0 && user.uid==u.uid}"> <td><a href="../NewsDetailServlet?nid=${u.nid}&op=show">查看</a></td> <td><a href="../NewsDetailServlet?nid=${u.nid}&op=update">修改</a></td> <td><a href="NewsDelete.jsp?nid=${u.nid}&title=${u.title}&userName=${user.userName}">删除</a></td> </c:when> <c:otherwise> <td><a href="../NewsDetailServlet?nid=${u.nid}&op=show">查看</a></td> </c:otherwise> </c:choose> </tr> </c:forEach> </table>
最新发布
06-01

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值