jquery向href属性添加变量
我相信这可能是我忽略了的一件简单的事情,但我一辈子都搞不清楚。非常感谢您的帮助 HTML 方法不是属性,因此需要使用jquery向href属性添加变量,jquery,href,attr,Jquery,Href,Attr,我相信这可能是我忽略了的一件简单的事情,但我一辈子都搞不清楚。非常感谢您的帮助 HTML 方法不是属性,因此需要使用.html()而不是.html var bookcourse = jQuery(".entry-title").html(); var booktime = jQuery(".ai1ec-time .ai1ec-field-value").html(); var booklocation = jQuery(".ai1ec-location .ai1ec-field-value"
.html()
而不是.html
var bookcourse = jQuery(".entry-title").html();
var booktime = jQuery(".ai1ec-time .ai1ec-field-value").html();
var booklocation = jQuery(".ai1ec-location .ai1ec-field-value").html();
var bookcost = jQuery(".ai1ec-cost .ai1ec-field-value").html();
演示:试试看
尝试:
试试这个
您也可以使用.text()
方法
$(document).ready(function()
var bookcourse = $(".entry-title").html();
var booktime = $(".ai1ec-time .ai1ec-field-value").html();
var booklocation = $(".ai1ec-location .ai1ec-field-value").html();
var bookcost = $(".ai1ec-cost .ai1ec-field-value").html();
$("#booklink").attr('href', "http://www.moxi.com.au/training-enrolement-form?title=" + bookcourse + "&cost=" + bookcost + "&date=" + booktime + "&location=" + booklocation);
});
.html()
是一个方法,您必须将其作为方法调用,因此必须编写
jQuery(“.entry title”).html()代码>
除此之外,.html()
返回元素中的所有html标记,我认为您必须使用text()
,这样文本将只包含在url中
为什么不使用text()
?如果您使用html()
Yep,您甚至可以在链接中包含html标记。。。像那样愚蠢的事。这肯定说明我盯着这个太久了。
http://www.moxi.com.au/training-enrolement-form?title=Installation Maintenance and Detailed Inspection&cost=AU$3200&date=January 13, 2014&location=MOXI Perth
var bookcourse = jQuery(".entry-title").html();
var booktime = jQuery(".ai1ec-time .ai1ec-field-value").html();
var booklocation = jQuery(".ai1ec-location .ai1ec-field-value").html();
var bookcost = jQuery(".ai1ec-cost .ai1ec-field-value").html();
jQuery(document).ready(function(){
var bookcourse = $(".entry-title").html();
var booktime = $(".ai1ec-time .ai1ec-field-value").html();
var booklocation = $(".ai1ec-location .ai1ec-field-value").html();
var bookcost = $(".ai1ec-cost .ai1ec-field-value").html();
jQuery("#booklink").attr('href', "http://www.moxi.com.au/training-enrolement-form?title=" + bookcourse + "&cost=" + bookcost + "&date=" + booktime + "&location=" + booklocation);
});
var href = $("#booklink").attr("href");
if (href.substr(0, href.length - 1) == "/") {
href = href.substr(0, href.length - 1);
}
href += "?title=" + $(".entry-title").text();
href += "?cost=" + $(".ai1ec-cost .ai1ec-field-value").text();
href += "?date=" + $(".ai1ec-time .ai1ec-field-value").text();
href += "?location=" + $(".ai1ec-location .ai1ec-field-value").text();
$("#booklink").attr("href", href);
$(document).ready(function()
var bookcourse = $(".entry-title").html();
var booktime = $(".ai1ec-time .ai1ec-field-value").html();
var booklocation = $(".ai1ec-location .ai1ec-field-value").html();
var bookcost = $(".ai1ec-cost .ai1ec-field-value").html();
$("#booklink").attr('href', "http://www.moxi.com.au/training-enrolement-form?title=" + bookcourse + "&cost=" + bookcost + "&date=" + booktime + "&location=" + booklocation);
});