mootools

preg_match in JavaScript?

天涯浪子 提交于 2019-11-27 01:43:26
问题 Is it possible in JavaScript to do something like preg_match does in PHP ? I would like to be able to get two numbers from string: var text = 'price[5][68]'; into two separated variables: var productId = 5; var shopId = 68; Edit: I also use MooTools if it would help. 回答1: JavaScript has a RegExp object which does what you want. The String object has a match() function that will help you out. var matches = text.match(/price\[(\d+)\]\[(\d+)\]/); 回答2: var text = 'price[5][68]'; var regex =

Change the options array of a select list

只谈情不闲聊 提交于 2019-11-26 20:55:25
问题 Is there a way to change the options array of an html select list using javascript or mootools? I need to replace the entire options set with a new one. In my ajax response I receive an array filled in with with the new HTML options, so I try to empty the old list and add new values as follows $('element').options.length=0; for (i=0; i<newSet.length; i++) { $('element').options[i]=newSet[i]; } The above code gives me an uncaught exception on the line inside the loop. uncaught exception:

Javascript detect scrollbar in textarea

狂风中的少年 提交于 2019-11-26 20:37:35
问题 I was wondering if anybody knows how I would go about detecting when the scrollbar appears inside a textarea . I am currently using mootools for my JavaScript and I am having issues getting it to detect a scrollbar. 回答1: function has_scrollbar(elem_id) { const elem = document.getElementById(elem_id); if (elem.clientHeight < elem.scrollHeight) alert("The element has a vertical scrollbar!"); else alert("The element doesn't have a vertical scrollbar."); } See this jsFiddle http://jsfiddle.net

How can I focus on an input field when a phonegap page loads?

限于喜欢 提交于 2019-11-26 18:28:29
问题 I would like to focus on a text input in a PhoneGap application when the page loads. I have tried the MooTools version $('entry').focus(); and document.getElementById('entry').focus() when the DOM is ready. This works fine when the HTML page is viewed in a normal web browser, but in the iPhone simulator running PhoneGap, it doesn't work. Is there a way to focus on a form field for iPhones that forces the virtual keyboard to appear? 回答1: As of iOS 6, the UIWebView class has a property called

Retrieve width/height of a css3 scaled element

大憨熊 提交于 2019-11-26 16:49:06
问题 I'm fighting against an oddity (I think) of the offsetWidth property. this is the scenario: I've got, let's say, a span tag, in my js, at a certain point I perform a css3 transform to this element, like: el.set('styles', { 'transform':'scale('+scale+', '+scale+')', /* As things would be in a normal world */ '-ms-transform':'scale('+scale+', '+scale+')', /* IE 9 */ '-moz-transform':'scale('+scale+', '+scale+')', /* Moz */ '-webkit-transform':'scale('+scale+', '+scale+')', /* Safari / Chrome */

mootools,jquery,dojo

自作多情 提交于 2019-11-26 16:28:43
最近,我开始关注Dojo了,Dojo是一个强大的面向对象JavaScript框架,既然我那么喜欢MooTools,也没理由不喜欢Dojo。与Dojo相比我对MooTools 和 jQuery 是比较熟的。这并不重要,不管使用什么样的语言,我们完成的任务是相同的,本质上的区别是使用的语法不同罢了。 接下来,我就来看一些不同JavaScript框架,如何使用一些基本的语法,来完成共同任务。 Execute Code when the DOM is Ready / window.load注册事件的替代方法 The Dojo Toolkit : 1 2 3 dojo.ready(function() {//do stuff}); The jQuery : 1 2 3 jQuery(document).ready(function() {//do stuff}); The MooTools : 1 2 3 window.addEvent('domready',function() {//do stuff}); Elements Style / 设置元素的样式 The Dojo Toolkit : 1 2 dojo.byId('myElement').style('background', 'blue');dojo.query('#id, .class, div').style(

jQuery and MooTools Conflict

可紊 提交于 2019-11-26 12:24:28
Okay, so I got jQuery to get along with MooTools with one script, by adding this at the top of the jQuery script: var $j = jQuery.noConflict(); and then replacing every: $( with $j( But how would you get MooTools to like the following script that using jQuery?? Thanks in advance for any input, Tracy //Fade In Content Viewer: By JavaScript Kit: http://www.javascriptkit.com var fadecontentviewer={ csszindex: 100, fade:function($allcontents, togglerid, selected, speed){ var selected=parseInt(selected) var $togglerdiv=$("#"+togglerid) var $target=$allcontents.eq(selected) if ($target.length==0){ /

Uncaught SyntaxError: Unexpected token :

淺唱寂寞╮ 提交于 2019-11-26 01:41:43
问题 I am running an AJAX call in my MooTools script, this works fine in Firefox but in Chrome I am getting a Uncaught SyntaxError: Unexpected token : error, I cannot determine why. Commenting out code to determine where the bad code is yields nothing, I am thinking it may be a problem with the JSON being returned. Checking in the console I see the JSON returned is this: {\"votes\":47,\"totalvotes\":90} I don\'t see any problems with it, why would this error occur? vote.each(function(e){ e.set(\

Comparing date part only without comparing time in JavaScript

只谈情不闲聊 提交于 2019-11-26 01:26:45
问题 What is wrong with the code below? Maybe it would be simpler to just compare date and not time. I am not sure how to do this either, and I searched, but I couldn\'t find my exact problem. BTW, when I display the two dates in an alert, they show as exactly the same. My code: window.addEvent(\'domready\', function() { var now = new Date(); var input = $(\'datum\').getValue(); var dateArray = input.split(\'/\'); var userMonth = parseInt(dateArray[1])-1; var userDate = new Date(); userDate

Cross domain iframe issue

倾然丶 夕夏残阳落幕 提交于 2019-11-25 21:44:15
问题 For say i have a Site called example.com on which iframe is embedded of domain iframe.net, now i want to read the content of iframe and pass some parameter to display a textual message. Like Hi with username. Now the problem is this able not able to make connection between the two , even am not able to get the innerHTML of iframe i used following approach document.getElementById(\'myframe\').contentWindow.document.body.innerHTML; It throws error \"Permission denied to access property\" Do