如何通过javascript更改链接HREF [英] How to change link HREFs via javascript

查看:117
本文介绍了如何通过javascript更改链接HREF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用户输入网址的表单。稍微调整后输入产生的值是变量#url,它会立即显示给用户。

I have a form where the user inputs an URL. The value resulting from that input after tweaking it a bit is the variable #url which is displayed to the user right away.

我需要制作类似和推文按钮我的网站指向该网址。使他们的HREFS等于变量#ur

I need to make the like and tweet buttons in my site point to that URL. Making their HREFS equal to the variable #url

这是分享按钮:

<a id="twtbutton" href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-via="theclocktwt">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div>

<fb:like id="fbbutton" send="false" layout="button_count" width="450" show_faces="false" font="" style="position: absolute; left:110px;"></fb:like>
</div>

在这里你可以看到它是如何工作的: http://www.chusmix.com/tests/magic.html

Here you can see how it works: http://www.chusmix.com/tests/magic.html

出现了什么因为改进的链接是我希望共享按钮使用的URL。

What appears as "Improved link" is the url I want the share buttons to use.

推荐答案

这是你想要做的 -

This is what you want to do -

var yourElement = document.getElementById('yourHref');
 yourElement.setAttribute('href', '#url');

这篇关于如何通过javascript更改链接HREF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆