我正在尝试调用一段特定的帖子元数据("购买门票"(以用作可点击的按钮。该代码在 Safari 中有效,但在其他浏览器中无效。我使用的是最新版本的Wordpress。以下是我目前正在使用的代码段:
<td>
<input type="button" value="Buy tickets"
onclick="window.open('<?php echo get_post_meta(get_the_ID(), 'Buy tickets', true); ?>')">
</td>
我也尝试使用以下脚本,但这会使按钮无法单击:
<td>
<button id="<?php $postId = get_the_ID(); echo $postId ?>" style="float:right">
<p>Buy tickets</p>
</button>
</td>
<script>
$(document).ready(function() {
// Handler for .ready() called.
$("#<?php $postId = get_the_ID(); echo $postId ?>").click(function(){
window.location="<?php echo get_post_meta(get_the_ID(), 'Buy tickets', true); ?>"
return false;
});
});
</script>
任何建议将不胜感激!要查看第一段代码的实际应用,请单击此处。
<form onsubmit="return false;">
<table class="tickets">
<tr>
<td><button data-goto="<?php echo get_post_meta(get_the_ID(), 'Buy tickets', true); ? >">Buy tickets</button></td>
</tr>
</table>
</form>
<script>
jQuery(document).ready(function($) {
$("table.tickets button").click(function(event) {
window.location.href = $(this).attr("data-goto");
});
});
</script>