通常,当您想让用户知道某些内容时,您会使用警报.
现在说我想这样做,但是在Android toast方式中,即一个弹出窗口显示,但几秒钟后自动消失,因此用户不必费心关闭它,如下图所示.
如何才能在网络上实现这样的目标?
注意:做一个触摸界面,这就是我想以这种方式拥有它的原因

我正在通过本教程快速开发网站Django.
我已完全遵循它(据我所知),但当我尝试查看索引页时收到以下错误:
NameError at /name 'views' is not defined
Exception location: \tuts\urls.py in <module>, line 12
Run Code Online (Sandbox Code Playgroud)
这是urls.py:
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^$', views.index, name='index'),
)
Run Code Online (Sandbox Code Playgroud)
这是views.py:
from django.shortcuts import render
# Create your views here.
def index(request):
items = Item.objects.order_by("-publish_date")
now = datetime.datetime.now()
return render(request,'portfolio/index.html', {"items": items, "year": now.year})
Run Code Online (Sandbox Code Playgroud)
这是models.py:
from django.db import models
# Create your models here. …Run Code Online (Sandbox Code Playgroud) 我正在使用javascript来隐藏一些基于用户角色的列表项.
我从列表项中获取角色text().当我将$("#activeUser").text()值与字符串进行比较时,它不起作用.
我在javascript中使用的HTML Block获取列表项的text()值.
<ul class="pull-right breadcrumb">
<li><a href="index.php">Home</a> <span class="divider">/</span> </li>
<li id="activeUser" class="active"> <?php echo ucfirst($_SESSION['sewafs_user_role']); ?> </li>
</ul>
Run Code Online (Sandbox Code Playgroud)
使用Javascript
$(document).ready(function () {
var testRole = $("#activeUser").text();
//This block of code works
role = 'Guest';
if (role == 'Guest') {
alert("Inside if");
$("#request_history_li").hide();
$("#assign_role_li").hide();
$("#volunteer_li").hide();
$("#profile_li").show();
$("#change_password_li").show();
}
//This doesn't work why?
if (testRole == 'Guest') {
alert("Inside if");
$("#request_history_li").hide();
$("#assign_role_li").hide();
$("#volunteer_li").hide();
$("#profile_li").show();
$("#change_password_li").show();
}
});
Run Code Online (Sandbox Code Playgroud)
但是如果我使用alert看到var testRole的值,它会打印Guest.
我尝试使用testRole.toString()/ string(testRole)方法将testRole值转换为字符串,但没有任何帮助.
请告诉我,我哪里出错了.谢谢.
我有一个文本输入.
我写了一个正则表达式来掩盖除了.和之外的所有特殊字符-.现在如果错误地用户.在输入中输入两个(点),那么使用当前的正则表达式
var valueTest='225..36'
valueTest.match(/[^-.\d]/)
Run Code Online (Sandbox Code Playgroud)
我预计这个数字不会通过这个条件
如何处理这种情况.我只想在输入字段中输入一个 .(点),因为它是一个数字.
我正在使用jquery UI和jQuery draggable,我的所有draggable都使用jquery clone helper并将draggable追加到droppable.
这是我的代码
$('#squeezePage #droppable').droppable({
tolerance: 'fit',
accept: '#squeezeWidgets .squeezeWidget',
drop: function(event, ui) {
var dropElem = ui.draggable.html();
var clone = $(dropElem).clone();
clone.css('position', 'absolute');
clone.css('top', ui.absolutePosition.top);
clone.css('left', ui.absolutePosition.left);
$(this).append(clone);
$(this).find('.top').remove();
$(this).find('.widgetContent').slideDown('fast');
$(this).find('.widgetContent').draggable({
containment: '#squeezePage #droppable',
cursor: 'crosshair',
grid: [20, 20],
scroll: true,
snap: true,
snapMode: 'outer',
refreshPositions: true
});
$(this).find('.widgetContent').resizable({
maxWidth: 560,
minHeight: 60,
minWidth: 180,
grid: 20,
});
}
});
Run Code Online (Sandbox Code Playgroud)
我用.css('top', ui.absolutePosition.top);和设置克隆css('left', ui.absolutePosition.left);的位置,但位置相对于BODY.
该位置与droppable无关,这使得可拖动的下降到随机位置.总体而言,可投放和可拖动的集成并不紧张.我想让它更顺畅.
我有一个脚本,在悬停时显示div并将其粘贴到光标上.
$(".picture_holder_thumb").mouseover(function () {
$(".title", this).show();
});
$(".picture_holder_thumb").mouseout(function () {
$(".title", this).hide();
});
$(document).bind('mousemove', function (e) {
$(".title", this).css({
left: e.pageX,
top: e.pageY
});
});
Run Code Online (Sandbox Code Playgroud)
它可以工作,但不知何故,粘性div和光标之间总是有很大的空间.
这是我的Div的CSS:
#img-container .captioning .title {
width: auto;
height:auto;
position: absolute;
float:left;
z-index:1;
display: none;
}
Run Code Online (Sandbox Code Playgroud)
我的JS有问题吗?我感谢任何帮助!
在这里你可以看到它的问题:http://www.cyrill-kuhlmann.de/index.php/projects
这是我从JS获得JS的示例小提琴:http://jsfiddle.net/hj57k/
如何更改每个元素,但最后一个元素保持原样?
jQuery(".diaryevent .field-name-field-category .field-items .field-item a")
.each(function(e)
{
var text = jQuery(this).text();
jQuery(this).html(text + ',');
});
Run Code Online (Sandbox Code Playgroud)
我需要添加eg not(":last-child")或:not(:last-child)
我想使用ng-include来渲染模板的侧边栏.该模板需要jQuery metisMenu插件用于下拉列表.
问题:插件仅在我在部分模板'sidebar.html'中加载以下脚本时才有效:
<script src="//cdnjs.cloudflare.com/ajax/libs/metisMenu/1.1.0/metisMenu.js"></script>
<script>$(function() {
$('#side-menu').metisMenu();
});</script>
Run Code Online (Sandbox Code Playgroud)
和失败当我尝试加载它们里面的index.html.
我想在index.html中只加载一次插件,因为我也可能在其他部分中需要它.这是一个工作模型的Plunker,它需要在partials中加载脚本.请注意,在将脚本从sidebar.html移动到index.html时,下拉菜单会停止工作.
任何帮助,将不胜感激.提前致谢.
我是这一切的新手,并且在使用 :contains 过滤一堆 div 时难以识别父元素?我的最终结果是有 3 个按钮,单击时检查 div 是否包含特定单词,如果是,则将一个类应用于包含的 div,并将另一个类应用于所有其他 div.. 基本上隐藏和显示它们。
我有一个小提琴不起作用,但显示了我正在尝试创建的想法。
我知道的代码不起作用,但给出的过程是;
$(".manchester").click(function (e) {
if ($('.address:contains("Manchester")').length) {
$('holder').addClass('visible');
}
if ($('.address:contains("London")').length) {
$('.holder').addClass('invisible');
}
if ($('.address:contains("Paris")').length) {
$('.holder').addClass('invisible');
}
e.preventDefault();
});
Run Code Online (Sandbox Code Playgroud)
我检查了许多网站,试图弄清楚这一点。但是,我没有运气,并认为我会继续在这里发帖。
我想要做的是根据 ID 设置 Active Accordion。下面,是我正在使用的。
jQuery代码:
$(function () {
$("#accordion").accordion({
collapsible: true,
header: "h3",
active: 'h3.content3',
heightStyle: "content"
});
});
Run Code Online (Sandbox Code Playgroud)
HTML:
<div id="accordion">
<h3 class="content1">Content Title</h3>
<div align="left">
<p>Content for 1 Goes Here</p>
</div>
<h3 class="content2">Content Title</h3>
<div align="left">
<p>Content for 2 Goes Here</p>
</div>
<h3 class="content3">Content Title</h3>
<div align="left">
<p>Content for 3 Goes Here</p>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我希望我解释得足够好,如果没有,请告诉我。我会尽力帮助你。
为什么这个插件不起作用?Firebug没有发现任何错误.
(function ($) {
$.fn.clearForm = function () {
return this.each(function () {
$(this).on("focus", function () {
$(this).val() = '';
});
});
};
}(jQuery));
Run Code Online (Sandbox Code Playgroud)
并在HTML中
<script>
$(this).clearForm();
Run Code Online (Sandbox Code Playgroud)
谢谢!