打印图片链接 [英] Link for printing image

查看:21
本文介绍了打印图片链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

其实我需要一点Java Script,但我绝对不擅长.所以我真的需要你的帮助.

我的问题是,我需要一个脚本,它将我从 id 的 url 保存到一个变量,并输出如下所示的变量:<a href="+ variable +">LINK</a>.

请注意,我想从中获取链接的 ID 位于页面中的某个位置,而脚本可能位于底部.

我的意思的例子:

<p>一些内容</p>

....<a href="+ 变量 +">LINK</a>...<脚本>变量 = getIdWhereNameIsURL;....

非常感谢您的帮助!

解决方案

首先,id="http://www.example.com" 可能看起来很奇怪,但应该没问题根据 HTML 5 规范.DIV 元素具有 NAME 属性也是不常见的.

其次,为您的 LINK 指定另一个 ID 会更容易,可能类似于 <a id="link_id">LINK</a>.

然后,您可以在脚本块中包含以下内容

var theDIV = document.getElementsByTagName("div")[0];//这里假设它是第一个 DIV,否则循环遍历元素//document.getElementsByName("url")[0].id 可能不起作用if (theDIV.name == "url") {var theLink = document.getElementById("link_id");theLink.href = theDIV.id;}

Actually I need a bit of Java Script, but I am definitely not good at it. So I would really need your help.

My problem is, that I would need a script, which saves me the url from an id to a variable and outputs the variable something like this: <a href="+ variable +">LINK</a>.

Note, that the ID, where I would like to get the link from, is somewhere in the page and the script likely at the bottom.

EXAMPLE OF WHAT I MEAN:

<div id="http://www.example.com" name="url">
  <p>Some content</p>
</div>
.
.
.
.
<a href="+ variable +">LINK</a>
.
.
.
<script>
   variable = getIdWhereNameIsURL;
   ....
</script>

Would really appreciate your help!

解决方案

First of all, id="http://www.example.com" may seems odd, but it should be OK per the HTML 5 specs. It is also unusual to have a NAME attribute for a DIV element.

Second, it will be easier to specify another id for your LINK, perhaps something like <a id="link_id">LINK</a>.

Then, you can have the below in your script block

var theDIV = document.getElementsByTagName("div")[0];
// here assuming it is the first DIV, otherwise, loop through the elements
// document.getElementsByName("url")[0].id may not work
if (theDIV.name == "url") {
  var theLink = document.getElementById("link_id");
  theLink.href = theDIV.id; 
}

这篇关于打印图片链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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