在javascript中设置超链接 [英] Setting hyperlinks in javascript

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

问题描述

当按下按钮时,学生姓名被添加到收藏夹框中



 function getFavourite()
{

name =学生1,


$(#output)。val($(#output)。val()+''+名称);
saveFavourites();
loadFavourites();
}







我想让学生成为链接的超链接回到学生的页面



这是我一直在尝试但没有运气



 name ='< a href ='+ window.location.href +'>'+'学生1,'+'/ a>'

解决方案

(#output)。val(


(#output)。val()+''+ name);
saveFavourites();
loadFavourites();
}







我想让学生成为链接的超链接回到学生的页面



这是我一直在尝试但没有运气



 name ='< a href ='+ window.location.href +'>'+'学生1,'+'/ a>'


你可以试试这个:

  var  a =  document  .createElement('  a'); 
var linkText = document .createTextNode( 您学生的文字);
a.appendChild(linkText);
a.title = 您学生的文字;
a.href = 你的网址;

// 您可以将其更改为附加在任何地方
< span class =code-sdkkeyword> document .body.appendChild(a);





这是你怎么做的用你的新元素追加你的div:

  function  getFavourite()
{
var name = document .createElement(' a');
var linkText = document .createTextNode( 学生1,);
name.appendChild(linkText);
name.title = 学生1,;
name.href = 您学生的网址;

// 这里你附加你的div或任何元素与新创建的'a'元件。

When a button is pressed the Student name is added to a favourites box

function getFavourite()
{

    name = "Student 1, " 


    $("#output").val($("#output").val() + ' ' + name);
    saveFavourites();
    loadFavourites();
}




I'm trying to get the student to be a hyperlink that links back to the student's page

This is what I've been trying but with no luck

name = '<a href=' + window.location.href + '>'  + 'Student 1, ' + '/a>'

解决方案

("#output").val(


("#output").val() + ' ' + name); saveFavourites(); loadFavourites(); }




I'm trying to get the student to be a hyperlink that links back to the student's page

This is what I've been trying but with no luck

name = '<a href=' + window.location.href + '>'  + 'Student 1, ' + '/a>'


You can try this:

var a = document.createElement('a');
var linkText = document.createTextNode("Text for your student");
a.appendChild(linkText);
a.title = "Text for your student";
a.href = "your url";

//you can change this to append anywhere
document.body.appendChild(a);



Here is how you can append your div with your new element:

function getFavourite()
{ 
   var name = document.createElement('a');
   var linkText = document.createTextNode("Student 1, ");
   name.appendChild(linkText);
   name.title = "Student 1, ";
   name.href = "your url for your student";
 
   //here you are appending your div or whatever element with a newly created 'a' element.


这篇关于在javascript中设置超链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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