即使是 php 格式,也无法在不重新加载整个页面的情况下运行我的选择事件。 <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel ="stylesheet" href = "style.css"> <script src="https://code.jquery.com/jquery-3.4.1.js"></script> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous"> <script src='https://kit.fontawesome.com/a076d05399.js'></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <script src = "home.js"></script> <title>Javascript on Steroids</title> </head> <body> <select id = "purchaseId" > <option value="1" selected >1</option> <option value="2">2</option> </select> </body> </html>您好,即使是 php 格式,也无法在不重新加载整个页面的情况下运行我的选择事件。 $myobject = document.getElementById("purchaseType"); $myobject.addEventListener("change",function(){ alert("tt"); })
3 回答
紫衣仙女
TA贡献1839条经验 获得超15个赞
您选择的 ID 不等于您在脚本中调用的 ID。此外,您可以将代码更改为:
$("#purchaseId").change(function() {
alert('tt')
});
这是一个小提琴。 https://jsfiddle.net/Lnroksgz/
湖上湖
TA贡献2003条经验 获得超2个赞
use this in script
myobject = document.getElementById("purchaseId");
myobject.addEventListener("change",function(){
alert("tt");
})
- 3 回答
- 0 关注
- 246 浏览
添加回答
举报
0/150
提交
取消
