Tag: JavaScript

if条件中的多个条件

如果我有一个if语句需要满足这些要求: if(cave > 0 && training > 0 && mobility > 0 && sleep > 0) 有什么方法可以说,他们都大于零? 只是为了更有效的干代码? 就像是: if(cave, training, mobility, sleep > 0)

如何检查jQuery插件和函数的存在?

我在一些页面有一个插件,但在其他一些页面我不想要它,所以我没有引用它的脚本文件。 在使用之前如何检查插件function是否存在。 在我的情况下,我正在使用这个插件:我这样使用它: $('#marquee-inner div').marquee('pointer').mouseover(function() { $(this).trigger('stop'); }).mouseout(function() { $(this).trigger('start'); }).mousemove(function(event) { if ($(this).data('drag') == true) { this.scrollLeft = $(this).data('scrollX') + ($(this).data('x') – event.clientX); } }).mousedown(function(event) { $(this).data('drag', true).data('x', event.clientX).data('scrollX', this.scrollLeft); }).mouseup(function() { $(this).data('drag', false); }); 我想要的是在调用这个选取框function之前进行检查,如果它存在与否。

可见性之间的性能差异:隐藏和显示:无

我想简化我的jQuery Backbone.js Web应用程序中的东西。 一个这样的简化是我的菜单和对话框小部件的行为。 以前我在开始时创build了我的菜单的div盒,并使用display: none; opacity:0;来隐藏它们display: none; opacity:0; display: none; opacity:0; 。 当我需要一个菜单​​,我改变了它的样式display:block然后使用jQuery的ui位置实用程序来定位div框(因为元素与display:none不能定位),当它完成后,最后改变其风格为opacity:1 。 现在,我只想隐藏它们visibility:hidden ,当我需要一个,我使用位置实用程序,然后将样式更改为visibility:visible 。 当我开始使用这种新的方法时,在整个Web应用程序会话中,我将有大约10个div box被隐藏,但占据空间,而之前的div box则隐藏着display:none 。 我的新方法有什么意义? 它在任何方面影响浏览器性能?

AngularJS + Jasmine:比较对象

我刚刚开始为我的AngularJS应用程序编写testing,并在Jasmine中这样做。 这里是相关的代码片段 ClientController: 'use strict'; adminConsoleApp.controller('ClientController', function ClientController($scope, Client) { //Get list of clients $scope.clients = Client.query(function () { //preselect first client in array $scope.selected.client = $scope.clients[0]; }); //necessary for data-binding so that it is accessible in child scopes. $scope.selected = {}; //Current page $scope.currentPage = 'start.html'; //For Client nav bar $scope.clientNavItems = [ {destination: […]

jQuery .on()方法没有看到新的元素

我得到一个JSON元素,并从它的项目,像这样构build一个列表: getTitles: function(data) { data = data || {}; var list = []; $.getJSON( '/titles', data, function(data) { $.each(data.data, function(key, val) { list.push( '<li><a href="'+ val.href +'">'+ val.title +'</a><span class="count">'+ val.count +'</span></li>' ) }); $('#title-items').html(list.join('')); } ); } 而我绑定点击事件a像这样a元素: $('a').on('click', function(e) { alert('clicked'); e.preventDefault(); }); 旧的元素显示警报,但新的跟随URL。 事件处理程序不适用于新的。 我该如何解决这个问题?

javascript:禁用文本select

我正在使用JavaScript来禁用我的网站上的文字select。 代码是: <script type="text/JavaScript"> function disableselect(e){ return false } function reEnable(){ return true } document.onselectstart=new Function ("return false") if (window.sidebar){ document.onmousedown=disableselect document.onclick=reEnable } </script> 类似的脚本可以在这里find: http : //rainbow.arch.scriptmania.com/scripts/no_right_click.html 在我的本地主机上:所有浏览器(Firefox,Chrome,IE和Safari)都很好用。 在我的Live站点上:除了Firefox之外,其他都可以。 我的问题是: 有没有人有一个build议,为什么Firefox的行为不同的现场和本地主机。 注意:Javascript已启用。 也许我的脚本太简单了,所以我尝试了以下完全相同的结果: http : //freeware.ke-zo.com/CODES/DisableRC.txt

包含至less8个字符,1个数字,1个大写和1个小写字母的javascript正则expression式

我想写一个正则expression式来validation密码,它必须符合下列条件: 至less包含8个字符 至less包含1个数字 包含至less1个小写字符(az) 包含至less1个大写字符(AZ) 仅包含0-9a-zA-Z 我尝试了以下,但似乎并没有工作。 http://jsfiddle.net/many_tentacles/Hzuc9/ <input type='button' value='click' class='buttonClick' /> <input type='text' /> <div></div> 和… $(".buttonClick").click(function () { if ($("input[type=text]").filter(function () { return this.value.match(/^(?=.*[0-9])(?=.*[az])(?=.*[AZ])([a-zA-Z0-9]{8})$/); })) { $("div").text("pass"); } else { $("div").text("fail"); } }); 有任何想法吗?

停止用户使用任何网页键盘的“Print Scrn”/“Printscreen”键

我目前正在做一个项目,在这个项目中,我需要停止用户拍摄任何网页的快照,为此他可以使用普通键盘上的“Print Scrn”/“Printscreen”键。 我一直在试图find解决办法,但徒劳无功。 如果可能的话,我需要考虑Firefox浏览器的“ Screengrab ”插件,也可以停止它。 任何帮助非常感谢,我正在使用PHP(作为服务器端语言)&jQuery为我的项目。

asp.net:无效的回发或callback参数

我得到这个错误: Server Error in '/' Application. Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid […]

如何检测铬和Safari浏览器(webkit)

我试图检测使用jQuery或JavaScript的铬和Safari浏览器。 我以为我们不应该使用jQuery.browser。 这里有什么build议吗? 非常感谢!