jQuery-将变量附加到URL,并在href中使用它 [英] JQuery - appending variable to URL, and use it in a href

查看:199
本文介绍了jQuery-将变量附加到URL,并在href中使用它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想不通...

有人可以帮我解释一下它是如何工作的吗?

Could someone please help me en explain how it works to?

目标: 将变量添加到硬编码的URL,然后将新字符串放入href

Goal: Adding a variable to a hard-coded URL, and put the new string into a href

示例:

var x = "1000";
var y = "http://www.google.com"
var result = y + x;

<a href="! the value of result !">click here...</a>

编辑,很抱歉,我的意思是y + x ...

Edit i'm sorry i meant y + x ofcourse...

推荐答案

给出以下HTML代码: <a href="" target="_blank">click here...</a>

Given this HTML code: <a href="" target="_blank">click here...</a>

您将需要以下js代码: (工作示例 http://jsfiddle.net/QUEZL )

You would need this bit of js code: (working example http://jsfiddle.net/QUEZL)

var x = "http://www.google.com/"
var y = "#q=test";

var result = x + y;
$('a').attr('href', result);

这篇关于jQuery-将变量附加到URL,并在href中使用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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