使用Java的Onclick

我一直在尝试通过单独的脚本实现JS调用,尽管引用了多个演示,但我无法使我的示例正常工作。

有人可以帮我解决这个简单的例子吗?

tescript.php说

<!DOCTYPE HTML>
<!-- Load checkout JS -->
<script type="text/javascript" src="tscript.js"></script>

<div class="col-md-3 col-sm-4 col-xs-12 imageUploadSide">
    <ul>
    <li> <button id="buyingPhoto" class="btn btn-buy">A New Buyit Button</button>   
   </li>
   </ul>
 </div>

然后脚本文件说

// checking script load & log
console.log("script file has been loaded")

$('#buyingPhoto').on('click', function() {
console.log("Can a button be depressed?")
});

我收到一个脚本已加载的控制台日志(故障排除步骤1),但onclick本身未运行

评论
一手的触碰
一手的触碰

You are missing to import jquery library .$()is jquey using

console.log("script file has been loaded")

$('#buyingPhoto').on('click', function() {
console.log("Can a button be depressed?")
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="col-md-3 col-sm-4 col-xs-12 imageUploadSide">
    <ul>
    <li> <button id="buyingPhoto" class="btn btn-buy">A New Buyit Button</button>   
   </li>
   </ul>
 </div>
点赞
评论
xsint
xsint

Your whole code is correct. You are have not included jquery library, just include the below CDN in your <head></head>section.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
点赞
评论