I'm developing a web application that uses PhoneGap:Build for a mobile version and want to have a single codebase for the 'desktop' and mobile versions. I want to be able to detect if PhoneGap calls will work (ie, is the user on a mobile device that will support PhoneGap). I've searched and cannot believe there is no simple way of doing this. Many people have offered suggestio
我正在开发一个Web应用程序,该应用程序使用PhoneGap:Build作为移动版本,并且希望为“桌面”和移动版本提供单个代码库。 我希望能够检测到PhoneGap调用是否可以工作(例如,移动设备上的用户是否支持PhoneGap)。 我搜索了,不敢相信没有简单的方法来做到这一点。 许多人提出了建议; http://www.sencha.com/forum/showthread.php?144127-Checking-if-running-in-PhoneGap-or-Mobile-Web-Browser http://groups.google.co
I'm developing a webapp (not a website with pages of interesting text) with a very different interface for touch (your finger hides the screen when you click) and mouse (relies heavily on hover preview). How can I detect that my user has no mouse to present him the right interface? I plan to leave a switch for people with both mouse and touch (like some notebooks). The touch event capabil
我正在开发一个非常不同的用于触摸的界面(当你点击时你的手指隐藏屏幕)和鼠标(很大程度上依赖于悬浮预览)来开发一个web应用程序(而不是一个包含有趣文本页面的网站)。 我如何检测到我的用户没有鼠标来为他提供正确的界面? 我打算为鼠标和触摸的人留下一个开关(就像一些笔记本一样)。 浏览器中的触摸事件功能实际上并不意味着用户正在使用触摸设备(例如,Modernizr不会剪切它)。 如果设备有鼠标,正确回答问题的
This question already has an answer here: How can you detect the version of a browser? 22 answers navigator.sayswho= (function(){ var ua= navigator.userAgent, tem, M= ua.match(/(opera|chrome|safari|firefox|msie|trident(?=/))/?s*(d+)/i) || []; if(/trident/i.test(M[1])){ tem= /brv[ :]+(d+)/g.exec(ua) || []; return 'IE '+(tem[1] || ''); } if(M[1]=== 'Chrome')
这个问题在这里已经有了答案: 你如何检测浏览器的版本? 22个答案 navigator.sayswho= (function(){ var ua= navigator.userAgent, tem, M= ua.match(/(opera|chrome|safari|firefox|msie|trident(?=/))/?s*(d+)/i) || []; if(/trident/i.test(M[1])){ tem= /brv[ :]+(d+)/g.exec(ua) || []; return 'IE '+(tem[1] || ''); } if(M[1]=== 'Chrome'){ tem= ua.match(/b(OPR|Edge
Is there a way to detect mobile devices using Javascript? Also, I researched that there are such an XML which contains user-agents that could help to identify the mobile handsets. You probably have a normal site and you want to redirect to a mobile site if certain conditions are met, like the screen is very small, or the content is zoomed out to fit on a large "virtual" screen in a s
有没有办法使用Javascript检测移动设备? 此外,我研究了有这样一个XML,其中包含可帮助识别手机的用户代理。 您可能拥有一个正常站点,并且如果满足某些条件(如屏幕非常小)或内容被缩小以适应小型物理空间中的大型“虚拟”屏幕,您希望重定向到移动站点。 那么,为什么不检查这些条件而不是测试一个数十亿个UA字符串。 尝试这样的事情: 为了UA报告屏幕的物理像素大小,该标签必须存在于html页面中。 * <meta name=
Is there a solid way to detect whether or not a user is using a mobile device in jQuery? Something similar to the CSS @media attribute? I would like to run a different script if the browser is on a handheld device. The jQuery $.browser function is not what I am looking for. Instead of using jQuery you can use simple JavaScript to detect it: if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IE
有没有一种可靠的方法来检测用户是否在jQuery中使用移动设备? 类似于CSS @media属性的东西? 如果浏览器位于手持设备上,我想运行其他脚本。 jQuery $.browser函数不是我正在寻找的。 您可以使用简单的JavaScript来检测它,而不是使用jQuery: if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) { // some code.. } 或者你可以将它们结合起来,使它更容易通过jQuery
This question already has an answer here: Do DOM tree elements with ids become global variables? 4 answers I am not sure about the historical perspective, but HTML 5 specifies that elements are candidates to be directly exposed as properties on the window object if they have an id attribute: The Window interface supports named properties. The supported property names at any moment consist
这个问题在这里已经有了答案: 使用ID做DOM树元素成为全局变量? 4个答案 我不确定历史观点,但HTML 5规定,如果元素具有id属性,则这些元素可作为window对象上的属性直接公开: Window接口支持命名属性。 受支持的属性名称随时包含以下内容(按树形顺序),忽略以后的重复项: [...] 活动文档中任何HTML元素的id内容属性的值与非空id内容属性。 这个定义的问题是它只保证如果有一个<div id="foo">
I'm having some images change on the value change of a <select> dropdown. I've simplified the code here to get the general idea across. Here's what I've got (let me know if you have any questions; I know I haven't shown 'select_text' in here but I don't think it's entirely necessary and I'd have to unravel a bunch of code to simplify here): var sel
我正在对<select>下拉列表中的值进行更改。 我在这里简化了代码以获得总体思路。 这里是我所得到的(如果您有任何疑问,请告知我;我知道我在这里没有显示'select_text',但我不认为这是完全必要的,我必须解开一堆代码以简化这里): var select_option_select = select_text.parent().find('select'); select_option_select.change(function(){ var changed_value = select_text.parent().find('select op
I have this div: <h1>$340</h1> I need to detect if inside of this div there is a dollar symbol, If so - remove it I'll explain again: I have got this code so far so I manage to detect if the symbol is in the div, but I can't figure how to remove it and update the DOM? var sign = $('h1').text(); if (sign.indexOf("$") >= 0) { //remove the sign } 使用简单
我有这个div: <h1>$340</h1> 我需要检测这个div里面是否有美元符号, 如果是这样 - 删除它 我会再解释一下:我已经得到了这段代码,所以我设法检测符号是否在div中,但我无法确定如何删除它并更新DOM? var sign = $('h1').text(); if (sign.indexOf("$") >= 0) { //remove the sign } 使用简单的正则表达式很容易var div = $('your selector here'); div.html(div.html().replace(/$/g, ''
Possible Duplicate: Checking if a string contains a certain substring I use the jQuery .val() method to get the value of a certain input field. How can I check if the returned string contains a certain character (for example, ',' )? In my specific application, I use the code: var tag_value = $("#tag_value").val(); to obtain comma-separated input values from the user, and I would
可能重复: 检查一个字符串是否包含某个子字符串 我使用jQuery .val()方法来获取某个输入字段的值。 如何检查返回的字符串是否包含某个字符(例如, ',' )? 在我的具体应用中,我使用的代码是: var tag_value = $("#tag_value").val(); 从用户获取以逗号分隔的输入值,并且我想检查该字符串是否包含任何逗号。 您可以将jQuery字符串的内容复制到一个变量中,并在其上使用indexOf: var tag_value=$("#tes
I have a jQuery array with a bunch of values. I want a user to be able to type into an input and have any partial matches to anything within my array display on the screen. So far, I've got it to know when there's a complete match, and I could print that to the page. But I'm not sure how to go about partial matches. Here's a JS Fiddle of what I have so far. Here's my
我有一堆价值的jQuery数组。 我想要一个用户能够输入一个输入,并有任何部分匹配我的数组显示在屏幕上的任何内容。 到目前为止,我已经知道何时有完整的匹配,并且可以将其打印到页面上。 但我不知道如何去部分匹配。 这是迄今为止我所拥有的JS小提琴。 这是我的代码,只是incase: var ingredients = ["cheese", "chicken", "cherries", "chick peas", "potato"] var input = $('#ingredient-search'); var value = i