jquery的新手,尝试制作一些没有成功的按钮 [英] New to jquery , trying to make some buttons without succes

查看:87
本文介绍了jquery的新手,尝试制作一些没有成功的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个令人尴尬的问题,我没有处理好jquery,我正在尝试制作一个或两个按钮,应该在某些表格上切换,但我无法指定哪个确切的形式,这就是为什么当我按下编辑时,所有评论都会显示一个编辑表单而不仅仅是一个,我试图修复它(通过为表单插入不同的ID),但我偶然发现了代码,如果有人可以帮助我,那将是很好的,如果不是对于偏离主题的抱歉...

这是代码

functions.php:

Hi, I have an embarrassing problem, I don't handle so well jquery , and I'm trying to make a button or two, that should toggle off and on some forms, but I don't manage to specify which exact form , and that's why when I push 'edit' a edit form will appear for all the comments not just for one , and I've tried to fix it(by inserting a different ID for forms) , but I stumble upon the code , If someone could help me it would be nice , if not sorry for being off-topic...
Here is the code
functions.php :

function get_comments($file_id) {
		include 'database.php';

		$result = mysqli_query($connect, "SELECT * FROM `comments` WHERE `file_id`='$file_id' AND `is_child`=FALSE ORDER BY `date` DESC");
		$row_cnt = mysqli_num_rows($result);

		echo '<h1>Comments ('.$row_cnt.')</h1>';
		echo '<div class="comment">';
			new_comment();
		echo '</div>';

		foreach($result as $item) {
			$date = new dateTime($item['date']);
			$date = date_format($date, 'M j, Y | H:i:s');
			$auth = $item['author'];
			$par_code = $item['com_code'];
// WHERE `par_code`='$par_code' AND `is_child`=TRUE    add_comment($item['author'], $item['com_code']);
			$chi_result = mysqli_query($connect, "SELECT * FROM `comments` WHERE `par_code`='$par_code' AND `is_child`=TRUE");
			$chi_cnt = mysqli_num_rows($chi_result);

			echo '<div class="comment" name="'.$item['com_code'].'">'
					.'<span class="author">'.$auth.'</span><br />'
					.$item['comment'].'<br />'
					.'<span class="date">Posted: '.$date.'</span><br />';

					if($chi_cnt == 0) {
						echo '<span class="replies">No replies</span>'
							.'<span class="replies"> Reply</span>'
							.add_comment($item['author'], $item['com_code']);;
					} else {
						echo '<span class="replies">[+] '.$chi_cnt.' replies</span>'
							.'<span class="replies" Reply</span>';
							add_comment($item['author'], $item['com_code']);
						echo '<div name="children" id="children">';
						foreach($chi_result as $com) {
							$chi_date = new dateTime($com['date']);
							$chi_date = date_format($chi_date, 'M j, Y | H:i:s');

							echo '<div class="child" name="'.$com['com_code'].'">'
									.'<span class="author">'.$com['author'].'</span><br />'
									.$com['comment'].'<br />'
									.'<span class="date">Posted: '.$chi_date.'</span><br />'
								.'</div>'
								.delete_comment()
								.edit_comment();
						}
						echo '</div>';
					}
				echo '</div>';
		}
		mysqli_close($connect);
	}

	function add_comment($reply, $code) {
		echo '<button class="button1">Reply</button><button class="button2">Edit</button><button class="button3">Delete</button>
		<form id="'.$code.'" action="reply.php" method="post" enctpye="" name="new_comment">'//
				.'<input type="hidden" name="par_code" value="'.$code.'" />'
				.'<textarea class="text_cmt" name="text_cmt" placeholder="Reply to '.$reply.'"></textarea><br />'
				.'<input type="submit" value="Reply" />'
			.'</form>';
	}

	function new_comment() {
		echo '<form action="new.php" method="post" enctpye="" name="new_comment">'
				.'<textarea class="text_cmt" name="text_cmt" placeholder="Post a new comment"></textarea><br />'
				.'<input type="submit" value="Post" />'
			.'</form>';
	}

	function delete_comment() {
		echo '<form action="delete.php" method="post" enctpye="" id="delete">'
				.'<input name="password" type="text" placeholder="Password to delete" id="password">'
				.'<input type="submit" value="Delete" />'
			.'</form>';
	}
	function edit_comment() {
		echo '<form action="edit.php" method="post" enctpye="" id="edit">'
				.'<textarea class="text_cmt" name="text_cmt"></textarea><br />'
				.'<input name="password" type="text" placeholder="Password to edit" id="password"><input type="submit" value="Edit" />'
			.'</form>';
	}

	function generateRandomString($length = 10) {
		$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
		$characterLength = strlen($characters);
		$randomString = '';

		for($i = 0; $i < $length; $i++) {
			$randomString .= $characters[rand(0, $characterLength - 1)];
		}
		return $randomString;
	}
	function checkString($com_code) {
		include 'database.php';

		$rand = generateRandomString();
		$result = mysqli_query($connect, "SELECT * FROM `comments` WHERE `com_code`='$com_code'");
		$row_cnt = mysqli_num_rows($result);

		if($row_cnt != 0) {
			return $rand;
		} else {
			checkString($rand);
		}
	}



index.php:


index.php :

<?php
	require_once 'database.php';
	require_once 'functions.php';
?>
<!doctype html>
<html>
	<head>
		<title>YouTube Comment Test</title>
		<link rel="stylesheet" href="styles.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
	</head>
	<body>
		<?php
			get_comments('1234');
		?>
<script> $('.button2').click(function() {$('form#edit').toggle();});</script>
<script> $('.button3').click(function() {$('form#delete').toggle();});</script>

	</body>
</html>



和这个 http://jsfiddle.net/46ww7v5L/1/ [ ^ ]是两个文件的结果,你可以看到当我点击一个按钮时,编辑/删除表单将显示所有注释,我只想要一个特定的...


and this http://jsfiddle.net/46ww7v5L/1/[^] is the result from the two file , you can see there that when I click one button , a edit/delete form will be displayed for all comments , I want just for a specific one...

推荐答案

file_id){
include ' database.php';

file_id) { include 'database.php';


result = mysqli_query(
result = mysqli_query(


connect, SELECT * FROM`comments` WHERE`file_id` ='
connect, "SELECT * FROM `comments` WHERE `file_id`='


这篇关于jquery的新手,尝试制作一些没有成功的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆