[英]I need help understanding how to use a javascript function in an onclick event in a php file
I created a javascript file, made a function, and then linked my html file with it in the head. 我创建了一个javascript文件,创建了一个函数,然后将我的html文件链接到头部。 It worked.
有效。 When I copy and pasted the exact same thing into a php file, the function suddenly doesn't work.
当我将完全相同的东西复制并粘贴到php文件中时,该函数突然不起作用。 I need a way to make the function work in the php file.
我需要一种方法使该函数在php文件中工作。
This is the javascript function: 这是javascript函数:
function showField(){
if(document.getElementById("downtown").checked && document.getElementById("pricerange").value == "100"){
document.getElementById("newField").removeAttribute("hidden");
}
}
This is the php where i try to call the function: 这是我尝试调用函数的php:
<input type="button" name = "search" value="Search" id="search" onclick="showField();">
This is in my head where I linked the javascript file: 这是我在链接javascript文件的地方:
<script src = "a3q5.js"></script>
Seeing that I don't know what the rest of your code is, I would just make sure you have the normal HTML stuff: 看到我不知道你的其余代码是什么,我只是确保你有正常的HTML东西:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<input type="button" name = "search" value="Search" id="search" onclick="showField();">
<script src = "a3q5.js"></script>
</body>
</html>
Hope this helps! 希望这可以帮助!
The simple way would be here, Put this to your PHP. 简单的方法就在这里,把它放到PHP上。 It worked for me
它对我有用
<?php
// your code
echo '<script src = "a3q5.js"></script>';
// your code
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.