按钮URL在某些浏览器中不起作用

时间:2012-05-16 19:22:29

标签: php wordpress internet-explorer

我正在尝试调用特定的帖子元数据(“购买票证”)作为可点击按钮。代码在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>

任何建议都将不胜感激!要查看第一段代码,请点击here

1 个答案:

答案 0 :(得分:0)

<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>