表达式喜欢Element.getAttribute("id")并Element.id返回相同的东西.
当我们需要HTMLElement对象的属性时应该使用哪一个?
有没有使用这些方法,如任何跨浏览器的问题getAttribute()和setAttribute()?
或者直接访问对象属性与使用这些属性方法之间的性能有何影响?
我在获取href的确切值方面遇到了麻烦.这是代码:
Link:
<a href="monthly"></a>
Script:
'a': function(target, process){
if(process == "stripe"){
document.location.href = "/accounts/stripe/payment"+target[0].href;
}else{
......
}
},
Run Code Online (Sandbox Code Playgroud)
如果我运行它,输出将是:
http://localhost:8000/accounts/stripe/paymenthttp://localhost:8000/monthly/
Run Code Online (Sandbox Code Playgroud)
请注意,localhost正在重复.如何在没有本地主机的情况下只获得href中的"月度"?我只尝试目标,但它未定义.我尝试目标[1],但它不起作用.
有时您在代码中写入文件的相对路径,因此在代码中,somefile.php当点击当然锚点会将您发送给href属性值时http://www.yourdomain.com/somefiles.php
现在我的问题是我可以以某种方式获得锚的完整href?
使用$(anchor).attr("href")时只获得相对路径.
大家好我有以下代码,
<ul class="post-buttons">
<li>
<a class="button icon-button thank-icon" title="Thank this post" href="./thank.php?f=12&p=249224"></a>
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
并在我的JavaScript上我有以下,
var ThankButton = $('div.thank-icon > a').attr('href');
console.log(ThankButton);
Run Code Online (Sandbox Code Playgroud)
但是在控制台日志中我得到的ThankButton没有定义,我在这里做错了什么?