相关疑难解决方法(0)

getAttribute()与Element对象属性?

表达式喜欢Element.getAttribute("id")Element.id返回相同的东西.

当我们需要HTMLElement对象的属性时应该使用哪一个?

有没有使用这些方法,如任何跨浏览器的问题getAttribute()setAttribute()

或者直接访问对象属性与使用这些属性方法之间的性能有何影响?

html javascript dom

92
推荐指数
2
解决办法
8万
查看次数

如何在没有域名的情况下获得确切的href值?

我在获取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],但它不起作用.

jquery

7
推荐指数
2
解决办法
3854
查看次数

如何获得完整的锚点href?

可能重复:
如何在JavaScript中获取"原始"href内容

有时您在代码中写入文件的相对路径,因此在代码中,somefile.php当点击当然锚点会将您发送给href属性值时http://www.yourdomain.com/somefiles.php

现在我的问题是我可以以某种方式获得锚的完整href?

使用$(anchor).attr("href")时只获得相对路径.

javascript anchor jquery href

6
推荐指数
2
解决办法
8900
查看次数

Java脚本获取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)

但是在控制台日志中我得到的ThankBut​​ton没有定义,我在这里做错了什么?

javascript jquery html5 href

2
推荐指数
1
解决办法
152
查看次数

标签 统计

javascript ×3

jquery ×3

href ×2

anchor ×1

dom ×1

html ×1

html5 ×1