- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
.slideDown 工作正常。第二次单击链接时,将再次出现 .slideDown 动画而不是 .slideUp。请帮帮我。谢谢。
$(document).ready(function() {
$('#toggleButton').click(function() {
if ($('#toggleSection').is(":hidden")) {
$('#toggleSection').slideDown("slow");
}
else {
$('#toggleSection').slideUp("slow");
}
return false;
});
});
下面是整个模块的代码。此 php 包含在主页中,其中还包含页眉和页脚。
<?php
/*
Written by: Daniel Kassner
Website: http://www.danielkassner.com
Originally posted on: http://www.wlscripting.com
Date: 09-13-2007 and last updated: 05-21-2010
*/
if (!function_exists('format_phone_us')) {
function format_phone_us($phone = '', $convert = true, $trim = true)
{
// If we have not entered a phone number just return empty
if (empty($phone)) {
return false;
}
// Strip out any extra characters that we do not need only keep letters and numbers
$phone = preg_replace("/[^0-9A-Za-z]/", "", $phone);
// Keep original phone in case of problems later on but without special characters
$OriginalPhone = $phone;
// If we have a number longer than 11 digits cut the string down to only 11
// This is also only ran if we want to limit only to 11 characters
if ($trim == true && strlen($phone)>11) {
$phone = substr($phone, 0, 11);
}
// Do we want to convert phone numbers with letters to their number equivalent?
// Samples are: 1-800-TERMINIX, 1-800-FLOWERS, 1-800-Petmeds
if ($convert == true && !is_numeric($phone)) {
$replace = array('2'=>array('a','b','c'),
'3'=>array('d','e','f'),
'4'=>array('g','h','i'),
'5'=>array('j','k','l'),
'6'=>array('m','n','o'),
'7'=>array('p','q','r','s'),
'8'=>array('t','u','v'),
'9'=>array('w','x','y','z'));
// Replace each letter with a number
// Notice this is case insensitive with the str_ireplace instead of str_replace
foreach($replace as $digit=>$letters) {
$phone = str_ireplace($letters, $digit, $phone);
}
}
$length = strlen($phone);
// Perform phone number formatting here
switch ($length) {
case 7:
// Format: xxx-xxxx
return preg_replace("/([0-9a-zA-Z]{3})([0-9a-zA-Z]{4})/", "$1-$2", $phone);
case 10:
// Format: (xxx) xxx-xxxx
return preg_replace("/([0-9a-zA-Z]{3})([0-9a-zA-Z]{3})([0-9a-zA-Z]{4})/", "($1) $2-$3", $phone);
case 11:
// Format: x(xxx) xxx-xxxx
return preg_replace("/([0-9a-zA-Z]{1})([0-9a-zA-Z]{3})([0-9a-zA-Z]{3})([0-9a-zA-Z]{4})/", "$1($2) $3-$4", $phone);
default:
// Return original phone if not 7, 10 or 11 digits long
return $OriginalPhone;
}
}
}
// Has the form been submitted?
if (isset($_POST['submit-add_student'])) {
// Convert the instrument and teacher to IDs
$resultIns = mysql_query("SELECT i_ID FROM instrument WHERE instrument_name = '$_POST[instrument]'");
$instID = mysql_fetch_row($resultIns);
$instID = $instID[0];
$resultTeach = mysql_query("SELECT f_ID FROM faculty WHERE last_name_fac = '$_POST[teacher]'");
$facID = mysql_fetch_row($resultTeach);
$facID = $facID[0];
// Seperate first and last name
$names = "$_POST[last_name]";
$namesArray = explode(" ", $names);
$firstName = $namesArray[0];
$lastName = $namesArray[1];
// The actual insert command
$ins = "INSERT INTO students (s_ID, last_name, first_name, phone, email_stu, instrument, teacher, year) VALUES (s_ID,'$lastName','$firstName','$_POST[phone]','$_POST[email_stu]','$instID','$facID','$_POST[year]')";
$resultStu = mysql_query($ins);
if(!$resultStu) {
die('Error: ' . mysql_error());
}
echo '<script language="javascript">';
echo 'window.location="index.php"';
echo '</script>';
}
// Has the DELETE form been submitted?
if (isset($_POST['submit_delete-stu'])) {
// The actual delete command
$stuDelete = "DELETE FROM students WHERE s_ID = '$_POST[ID]'";
$resultStuDelete = mysql_query($stuDelete);
if(!$resultStuDelete) {
die('Error: ' . mysql_error());
}
echo '<script language="javascript">';
echo 'window.location="index.php"';
echo '</script>';
}
// Toggle the display order
$order = $_GET['order'];
if (empty($order)) {
$orderBy="ASC";
$order="down";
}
else {
if ($order=="up") {
$orderBy="ASC";
$order="down";
}
elseif ($order=="down") {
$orderBy="DESC";
$order="up";
}
}
// Change the sort parameter
$sort = $_GET['sort'];
if (empty($sort)) {
$sort="students.last_name";
}
else {
switch ($sort) {
case "name":
$sort="students.last_name";
break;
case "phone":
$sort="phone";
break;
case "email":
$sort="email_stu";
break;
case "inst":
$sort="instrument";
break;
case "teacher":
$sort="teacher";
break;
case "year":
$sort="year";
break;
}
}
// Display the table header links
echo "<div class=\"list\">";
echo "<div class=\"row-header\">";
echo "<div class=\"sort\"><a href=\"index.php?sort=name&order=" . $order . "\">Name";
echo ($sort=="students.last_name") ? (($order=="up") ? " ▼" : " ▲") : " ";
echo "</a></div>";
echo "<div class=\"sort\"><a href=\"index.php?sort=phone&order=" . $order . "\">Phone";
echo ($sort=="phone") ? (($order=="up") ? " ▼" : " ▲") : " ";
echo "</a></div>";
echo "<div class=\"sort\"><a href=\"index.php?sort=email&order=" . $order . "\">Email";
echo ($sort=="email_stu") ? (($order=="up") ? " ▼" : " ▲") : " ";
echo "</a></div>";
echo "<div class=\"sort\"><a href=\"index.php?sort=inst&order=" . $order . "\">Instrument";
echo ($sort=="instrument") ? (($order=="up") ? " ▼" : " ▲") : " ";
echo "</a></div>";
echo "<div class=\"sort\"><a href=\"index.php?sort=teacher&order=" . $order . "\">Teacher";
echo ($sort=="teacher") ? (($order=="up") ? " ▼" : " ▲") : " ";
echo "</a></div>";
echo "<div class=\"sort\"><a href=\"index.php?sort=year&order=" . $order . "\">Year";
echo ($sort=="year") ? (($order=="up") ? " ▼" : " ▲") : " ";
echo "</a></div>";
?>
<div id="arrow">←</div><div id="helper">Use these links to the left to sort the info.</div>
<?php
if ($username == "admin") {
?>
<button id="toggleButton">Show/Hide Inputs</button>
<?php
}
echo "</div>";
// Display the input forms if admin is logged in
$username = $_COOKIE['ID_my_site'];
if ($username == "admin") {
?>
<div id="toggleSection">
<div class="row-input">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<div class="name"><input type="text" id="students" name="last_name" maxlength="40" value="Full Name"></div>
<div class="phone"><input type="text" id="students" name="phone" maxlength="40" value="Phone"></div>
<div class="email"><input type="text" id="students" name="email_stu" maxlength="40" value="Email"></div>
<div class="inst">
<select name="instrument">
<?php $instrument = mysql_query("SELECT instrument_name FROM instrument ORDER BY instrument_name ASC");
while($row = mysql_fetch_array($instrument)) {echo "<option>" . $row['instrument_name'] . "</option>";}?>
</select></div>
<div class="teacher">
<select name="teacher">
<?php $teacher = mysql_query("SELECT last_name_fac FROM faculty ORDER BY last_name_fac ASC");
while($row = mysql_fetch_array($teacher)) {echo "<option>" . $row['last_name_fac'] . "</option>";}?>
</select></div>
<div class="year">
<select name="year">
<option>FR</option>
<option>SO</option>
<option>JR</option>
<option>SR</option>
<option>GR1</option>
<option>GR2</option>
<option>DMA</option>
</select>
</div>
<div id="actions-add"><input type="submit" src="/images/add-icon.png" name="submit-add_student" class="add" value="Add"/></div>
</form>
</div>
</div>
<?php
}
// Display the information
$result = mysql_query("SELECT * FROM students LEFT JOIN faculty ON students.teacher = faculty.f_ID LEFT JOIN instrument ON students.instrument = instrument.i_ID ORDER BY $sort $orderBy");
$i = 0;
while($row = mysql_fetch_array($result))
{
$phone = $row['phone'];
if ($i % 2 ==0)
{
echo "<div class=\"row\">";
$i++;
}
else
{
echo "<div class=\"row-alternate\">";
$i++;
}
echo "<div class=\"name\">" . $row['first_name'] . " " . $row['last_name'] . "</div>";
echo "<div class=\"phone\">" . format_phone_us($phone) . "</div>";
echo "<div class=\"email\"><a href=\"mailto:" . strtolower($row['email_stu']) . "\">" . strtolower($row['email_stu']) . "</a></div>";
echo "<div class=\"inst\">" . $row['instrument_name'] . "</div>";
echo "<div class=\"teacher\">" . $row['first_name_fac'] . " " . $row['last_name_fac'] . "</div>";
echo "<div class=\"year\">" . $row['year'] . "</div>";
if ($username == "admin") { // Display the delete button if admin is logged in
echo "<div class=\"actions\">";?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="hidden" name="ID" value="<?php echo $row['s_ID'];?>">
<input type="submit" src="/images/delete-icon.png" class="delete" name="submit_delete-stu" value="">
</form>
<?php
echo "</div>"; }
echo "</div>";
}
echo "</div>";
?>
最佳答案
根据评论,我认为重要的是要注意 live()
已贬值:
live() is depreciated now (as of 1.7 and removed as of 1.8). You should use on() like so (example): $(document).on("click", "#toggleButton", function() {});. You can narrow down document, as long as it exists as a DOM element on page load. Documentation
我会使用 .slideToggle()对于这个问题。不要把它和它的姐妹混淆.fadeToggle()
$(document).ready(function() {
$('#toggleButton').click(function() {
$('#toggleSection').slideToggle('slow');
});
});
更少的代码,而且做同样的事情,对吧。
.fadeToggle()
: http://jsfiddle.net/TYcWg/1/ HTML
我在 livexample 中使用
<button id="toggleButton">Bacon Me</button>
<div id="toggleSection">Bacon ipsum dolor sit amet
pork chop magna pork, tempor in jowl ham labore rump
tenderloin pariatur pancetta tri-tip pork loin.
Spare ribs meatloaf ground round chicken, non esse cow.
</div>
查看您的实际代码,我无法重现该问题。 http://jsfiddle.net/zXwRB/我在 chromium 12.0.742.91 和 firefox 3.6 中试过这个
根据您的评论,我想知道是否将其包装在 .live() 中将是正确的方法。
$(document).ready(function() {
$('#toggleButton').live('click', function() {
$('#toggleSection').slideToggle('slow');
});
});
不幸的是,如果没有看到更多您的代码,可能很难确定。
我建议 .live()
因为 API 中的以下段落
The .live() method is able to affect elements that have not yet been added to the DOM through the use of event delegation: a handler bound to an ancestor element is responsible for events that are triggered on its descendants. The handler passed to .live() is never bound to an element; instead, .live() binds a special handler to the root of the DOM tree.
如果您稍后可能会通过 PHP 添加项目,则可能会出现一些冲突……这是我在没有看到代码的情况下的最佳猜测。
关于php - jQuery .slideUp 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6514985/
在带有 jQuery 的 CoffeeScript 中,以下语句有什么区别吗? jQuery ($) -> jQuery -> $ - > 最佳答案 第一个与其他两个不同,就像在纯 JavaScr
已关闭。这个问题是 off-topic 。目前不接受答案。 想要改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 已关闭13 年前。 Improve th
就目前情况而言,这个问题不太适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、民意调查或扩展讨论。如果您觉得这个问题可以改进并可能重新开放,visit
这个问题可能听起来很愚蠢,但请耐心等待,因为我完全是初学者。我下载了两个 jQuery 版本,开发版本和生产版本。我想知道作为学习 jQuery 的初学者,什么更适合我。 最佳答案 如果您对 jQue
The documentation说要使用 1.6.4,但我们现在已经升级到 1.7.2。 我可以在 jQuery Mobile 中使用最新版本的 jQuery 吗? 最佳答案 您当然可以,但如果您想
我在这里看到这个不错的 jquery 插件:prettyphoto jquery lightbox有没有办法只用一个简单的jquery来实现这样的效果。 我只需要弹出和内联内容。你的回复有很大帮助。
很明显我正在尝试做一些 jQuery 不喜欢的事情。 我正在使用 javascript 上传图片。每次上传图片时,我都希望它可见,并附加一个有效的删除脚本。显示工作正常,删除则不然,因为当我用 fir
这两个哪个是正确的? jQuery('someclass').click(function() { alert("I've been clicked!"); }); 或 jQuery('somec
我正在寻找一个具有以下格式的插件 if (jQuery)(function ($) { -- plugin code -- })(jQuery); 我明白 (function ($)
关闭。这个问题是opinion-based 。目前不接受答案。 想要改进这个问题吗?更新问题,以便 editing this post 可以用事实和引文来回答它。 . 已关闭10 年前。 Improv
我知道这个问题已经被问过几次了,但想知道您是否可以帮助我解决这个问题。 背景:我尝试创建一个使用 Ajax 提交的表单(jQuery 表单提交)。我已经工作得很好,然后我想在表单上得到验证。我可以使用
我正在使用无处不在的jquery validate plugin用于表单验证。它支持使用metadata plugin用于向表单元素添加验证规则。 我正在使用此功能。当验证查找这些规则时,它会对元素进
我更喜欢为我一直在开发的网络社区添加实用的视觉效果,但随着事情开始堆积,我担心加载时间。 拥有用户真的更快吗加载(希望是缓存的)副本来自 Google 存储库的 jquery? 是否使用 jQuery
这个问题已经有答案了: Slide right to left? (17 个回答) 已关闭 9 年前。 你能告诉我有没有办法在 jQuery 中左右滑动而不使用 jQuery UI 和 jQuery
我如何找出最适合某种情况的方法?任何人都可以提供一些示例来了解功能和性能方面的差异吗? 最佳答案 XMLHttpRequest 是原始浏览器对象,jQuery 将其包装成一种更有用和简化的形式以及跨浏
运行时 php bin/console oro:assets:build ,我有 11 个这样的错误: ERROR in ../node_modules/jquery-form/src/jquery.
我试图找到 jQuery.ajax() 在源代码中的定义位置。但是,使用 grep 似乎不起作用。 在哪里? 谢谢。 > grep jQuery.ajax src/* src/ajax.js:// B
$.fn.sortByDepth = function() { var ar = []; var result = $([]); $(this).each(function()
我的页面上有多个图像。为了检测损坏的图像,我使用了在 SO 上找到的这个。 $('.imgRot').one('error',function(){ $(this).attr('src','b
我在理解 $ 符号作为 jQuery 函数的别名时遇到了一些麻烦,尤其是在插件中。你能解释一下 jQuery 如何实现这种别名:它如何定义 '$' 作为 jQuery 函数的别名?这是第一个问题。 其
我是一名优秀的程序员,十分优秀!