0
実現後、私は自分のウェブサイト上の任意のjavascriptにwp_enqueue_scriptを使用する必要があり、wp_enqueue_scriptを使用しようとしています。wp_enqueue_scriptに渡すとスクリプトが動作しない
私の.phpファイルが含まれています:
<?php
function EnactScript(){
wp_register_script('CommercePlugin', plugins_url('js/CouponGenerator.js', __FILE__), array('jquery'), '', false);
wp_enqueue_script('CommercePlugin');
}
add_action('wp_enqueue_scripts', 'EnactScript');
function GenCoupon(){
echo "<input type = \"button\" onclick = \"randomCoupGen(); this.disabled = true\">Click here to see if you won!!</input>";
echo '<imgr src="' . plugins_url('js/CouponGenerator.js', __FILE__) . '" > ';
}
add_filter('woocommerce_before_checkout_form', 'GenCoupon', 9999999, 2);
?>
これはCouponGenerator.jsコード:
<html>
<head>
<script type = "text/javascript">
function randomCoupGen()
{
var RanNum = Math.floor(Math.random() * 6);
if(RanNum == 1)
{
alert("You rolled a 1");
}
else if(RanNum == 2)
{
alert("You rolled a 2.");
}
else
{
alert("You rolled something other than 1 or 2");
}
}
</script></head><body></body></html>
私はときwp_head()私のJSが読み込まなっていることを確認するために行うには何が必要です;と呼ばれる?
。私はスクリプトとHTMLタグを取り去ったと思います。どうもありがとうございます。 – crnafus