【发布时间】:2013-12-05 14:19:25
【问题描述】:
我确定这可能是我忽略的一些简单的事情,但我一生都无法弄清楚。非常感谢任何帮助。
HTML
<h1 class="entry-title">Installation Maintenance and Detailed Inspection</h1>
<div class="ai1ec-time">
<div class="ai1ec-label">When:</div>
<div class="ai1ec-field-value">January 13, 2014</div>
</div>
<div class="ai1ec-location">
<div class="ai1ec-label">Where:</div>
<div class="ai1ec-field-value">MOXI Perth</div>
</div>
<div class="ai1ec-cost">
<div class="ai1ec-label">Cost:</div>
<div class="ai1ec-field-value">AU$3200</div>
</div>
<a id="booklink" title="Training Enrolement Form" href="http://www.moxi.com.au/training-enrolement-form/">Book Now!</a>
jQuery
<script>
jQuery(document).ready(function(){
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("#booklink").attr('href',"http://www.moxi.com.au/training-enrolement-form?title="+bookcourse+"&cost="+bookcost+"&date="+booktime+"&location="+booklocation);
});
</script>
目标是将 href 属性输出为:
http://www.moxi.com.au/training-enrolement-form?title=Installation Maintenance and Detailed Inspection&cost=AU$3200&date=January 13, 2014&location=MOXI Perth
【问题讨论】:
-
为什么不使用
text()?如果您使用html(),您甚至可以在链接中包含 html 标记