【发布时间】:2015-12-02 06:52:28
【问题描述】:
我已经阅读了很多解决方案,并且我读到我应该使用“on”jquery。但它对我不起作用。
我有一个通常适用于日历选择器的字段。我有一个按钮,当我单击此按钮时,会为 div 充值,并为日历选择器功能添加一个具有相同 id 的字段。 但显然该按钮不起作用。在日历选择器上它也不起作用。 我想在 div 中拥有按钮和文本字段,并发出 Ajax 请求以继续操作日历选择器。
test.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="X-UA-Compatible" content="IE=8">
<title>
</title>
<link rel='stylesheet' type='text/css' href='../css/jquery-ui-1.9.2.custom.css'/> <!--Carga los estilos de jquery-->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="../js/jquery-ui-1.9.2.custom.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#generateDiv").click(function() {
$.ajax({
type:"POST",
url: "ajax.php"
}).done(function(data) {
$("#divReloaded").html(data);
});
})
$( "#fecha" ).datepicker({ dateFormat: 'yy-mm-dd' });
})
</script>
<!--Fin enlaces-->
</head>
<body>
<div id='divReloaded'>
<input type='text' id='fecha'>
<input type='button' id='generateDiv' value='button' >
</div>
</body>
</html>
ajax.php
<?php
echo "not works jquery :(<br>";
echo "<input type='text' id='fecha'>";
echo "<input type='button' id='generateDiv' value='button' >;"
?>
【问题讨论】:
-
您是否在控制台中看到任何反馈?
-
尝试使用 on('click', element, callback) 而不是 click(callback)
-
@AdamJeffers 感谢您的回答。我在控制台中没有错误。
-
console.log(data) 并在您的完成功能中为我们发布
-
@bmalets
$("#generateDiv").on("click", "#fecha #generateDiv", function() {按钮不起作用
标签: javascript php jquery css ajax