我有这段代码.我正在尝试关闭div,当在Div之外点击时,我已经搜索了这个论坛但找不到解决方案 - 这是一个小提琴 - 演示
$('#hideshow1').on("click", function() {
var text = $(this).val();
$("#req").toggle();
});
$(window).on("click keydown", function(e) {
//e.preventDefault() /*For the Esc Key*/
if (e.keyCode === 27 || !$(e.target).is(function() {return $("#req, #hideshow1")})) {
$("#req").hide()
}
}).focus()
Run Code Online (Sandbox Code Playgroud) 问题是我无法在没有重新加载的情况下在我的数据库中插入数据我已经测试了它没有note_sql.js和我的note_sql.php工作正常但是我的js文件中似乎有问题,如果有些身体可以指向我正确的方向它会很棒
的index.php
<form id="noteform" action="note_sql.php" method="POST">
<input type="text" name="note"></input>
<input id="sub" type="submit" value="Save Note" />
</form>
<span id="result_note"><span>
<script type ="text/javascript" src="jquery/note_sql.js"></script>
Run Code Online (Sandbox Code Playgroud)
note_sql.js
$("#sub").click(function(){
var data = $("#noteform: input").serializeArray();
$.post($("#noteform").attr("action"),data,function(info){$("result_note").html(info); });
clearInput();
});
$("#noteform").submit(function(){
return false;
});
function clearInput(){
$("#noteform :input").each(function(){
$(this).val('');
});
}
Run Code Online (Sandbox Code Playgroud) 我无法附加页面只是似乎刷新我想要查看它而不刷新页面
的index.php
<div class="view_comment">
<b>username :</b> <?php echo $comment_comment;?>
</div>
<div id="comment_type_area" class="comment_type_area">
<form method="POST">
<input type="text" class="comment" post_id="<?php echo $shared_id2; ?>" id="text_comment" placeholder="Write a Comment"></input>
<input type="submit" id="post_button" ></input>
</form>
</div>
Run Code Online (Sandbox Code Playgroud)
的jquery.js
$(document).ready(function(){
$('.comment').keydown(function (e){
if(e.keyCode == 13){
var post_id = $(this).attr('post_id');
var comment = $(this).val();
$.post('/comment.php',{ post_id: post_id, comment:comment});
$('.comment').val('');
/*i am guessing the problem starts from here and onwards*/
$(this).parent().children('.comments').append("<div class='view_comment'><b>Username :</b>" + comment +"</div>");
}
});
});
Run Code Online (Sandbox Code Playgroud)