当我将按钮插入到echo中时,无法点击按钮。。
echo '<input onclick="window_target = document.basicForm.maparea1;
window_name = window.open("search.php",
"window_name",
"resizable=0,location=0,directories=0,status=0,top=30,left=100,toolbar=no,width=180,height=480,menubar=no,scrollbars=no"
);
window_name.window_target = window_target
" value="Select" type="button">';
欢迎使用现代JS:尽量不要使用onclick
,或者直接嵌入HTML中的任何on...
处理程序。相反,生成您的页面以执行以下操作:
<!doctype html>
<html>
<head>...</head>
<body>
<input type="..." id="spawnClickerThing" ...>
...
<script src="mypagescript.js"></script>
</body>
</html>
(所以不是PHP echo/printed!)然后在javascript include中,执行所有事件绑定等:
...
function newWindowHandling(avt) {
var window_target = document.basicForm.maparea1;
var window_name = window.open("search.php", "window_name", "...");
window_name.window_target = window_target;
}
function setEverythingUp() {
document.removeEventListener("DOMContentLoaded", setEverythingUp);
var inputclicker = document.querySelector("#spawnClickerThing");
inputclicker.addEventListener("click", newWindowHandling);
}
document.addEventListener("DOMContentLoaded", setEverythingUp);
根据您是否使用库来实现更高效的JavaScript,代码可以被压缩,但一般原则是成立的。不要使用PHP注入JS"内联",它非常脆弱,无法维护。将脚本保存在易于编辑的.js文件中,独立于为页面生成HTML源代码的.php脚本。
转义引号
echo '<input onclick="window_target = document.basicForm.maparea1; window_name = window.open(''search.php'', ''window_name'', ''resizable=0,location=0,directories=0,status=0,top=30,left=100,toolbar=no,width=180,height=480,menubar=no,scrollbars=no''); window_name.window_target = window_target" value="Select" type="button">';
你不能用这种方式工作,你必须使用
你必须在javascript中使用这样的代码。我假设你有jquery包含的
$(document).on('click', '.btninline' ,function() {
window_target = document.basicForm.maparea1;
window_name = window.open("search.php", "window_name","resizable=0,location=0,directories=0,status=0,top=30,left=100,toolbar=no,width=180,height=480,menubar=no,scrollbars=no");
window_name.window_target = window_target;
}
然后在您的php 中
echo '<input class="btninline" value="Select" type="button">';