Showing a page content at once

I have a website which contains some images in index.php The problem I am facing is the whole page is not loading at once, I think images are taking some time to load So what I have done is, I am showing an loading image at first and then after some time I am showing the page, that resolves the problem. But I am curious to know is there any other better way to do this? I prefer to optimise

一次显示页面内容

我有一个网站,其中包含index.php中的一些图像 我面临的问题是整个页面不能立即加载,我认为图像需要一些时间才能加载 所以我所做的是,我首先显示一个加载图像,然后在显示页面一段时间后,解决了问题。 但我很想知道是否还有其他更好的方法可以做到这一点? 我更喜欢优化我的图像。 PNG图像 你可以使用pngcrush为你优化你的PNG文件,但是我个人发现,一旦我完成了它,pngcrush只能成功地扩大它。 尽可能使用Index

render multiple responses in one action

I have an ajax request in my rails app that returns a variable from my controller action. Inside the controller action I have a loop that can take some time to get through. Controller def myAction $j = 1 until $j > list_size do array << { :foo => $j } $j +=1; end @myvariable = array.to_json end myAction.js.erb var myVariable = JSON.parse("<%= escape_j

在一个动作中呈现多个响应

我的Rails应用程序中有一个ajax请求,它从我的控制器操作返回一个变量。 在控制器动作内部,我有一个循环,需要一些时间才能完成。 调节器 def myAction $j = 1 until $j > list_size do array << { :foo => $j } $j +=1; end @myvariable = array.to_json end myAction.js.erb var myVariable = JSON.parse("<%= escape_javascript(raw @myvariable) %>"); for (var k = 0; k

How do I get the value of text input field using JavaScript?

I am working on a search with JavaScript. I would use a form, but it messes up something else on my page. I have this input text field: <input name="searchTxt" type="text" maxlength="512" id="searchTxt" class="searchField"/> And this is my JavaScript code: <script type="text/javascript"> function searchURL(){ window.location = "http://www.myurl.com/search/" + (input text va

如何使用JavaScript获取文本输入字段的值?

我正在使用JavaScript进行搜索。 我会使用一个表单,但它会弄乱我的页面上的其他内容。 我有这个输入文本字段: <input name="searchTxt" type="text" maxlength="512" id="searchTxt" class="searchField"/> 这是我的JavaScript代码: <script type="text/javascript"> function searchURL(){ window.location = "http://www.myurl.com/search/" + (input text value); } </script> 我如何从文

How do I output an ISO 8601 formatted string in JavaScript?

I have a Date object. How do I render the title portion of the following snippet? <abbr title="2010-04-02T14:12:07">A couple days ago</abbr> I have the "relative time in words" portion from another library. I've tried the following: function isoDate(msSinceEpoch) { var d = new Date(msSinceEpoch); return d.getUTCFullYear() + '-' + (d.getUTCMonth() + 1) + '-'

如何在JavaScript中输出ISO 8601格式的字符串?

我有一个Date对象。 如何渲染以下代码片段的title部分? <abbr title="2010-04-02T14:12:07">A couple days ago</abbr> 我有另一个图书馆的“文字相对时间”部分。 我试过以下内容: function isoDate(msSinceEpoch) { var d = new Date(msSinceEpoch); return d.getUTCFullYear() + '-' + (d.getUTCMonth() + 1) + '-' + d.getUTCDate() + 'T' + d.getUTCHours() + ':' + d.getUTCMinutes() +

Converting Date to JS Date Object

I have a date in a weird format and I am not sure how to turn it into a JS Date Object. I am sure libraries like moment.js have utilities for this but I don't really want to load an entire library just for this conversion. Here is the data: /Date(1472586116588-0400)/ EDIT: I have updated the back end code to use a string in the JSON instead of a C# Date time and then I convert the DateT

将日期转换为JS日期对象

我有一个奇怪的格式的日期,我不知道如何把它变成一个JS日期对象。 我相信像moment.js这样的库有这样的工具,但我并不想仅仅为这个转换加载整个库。 这里是数据: /日期(1472586116588-0400)/ 编辑:我已经更新后端代码,以在JSON中使用字符串而不是C#日期时间,然后按照以下方式转换DateTime: Date.ToString("s"); 这给了我这个字符串:2016-09-02T10:13:12 所以现在我的问题是,如果我做var date = new Date(

Javascript date string passed to Date constructor gives strange results

Why do I get such differing results with similarly formatted date strings when creating a new date? CHROME (43.0.2357.134 m) console: new Date('2014-12-25') Wed Dec 24 2014 17:00:00 GMT-0700 (Mountain Standard Time) [Chrome assumes Z with 00:00 (utc) and returns that local time] new Date('2014-1-25') Sat Jan 25 2014 00:00:00 GMT-0700 (Mountain Standard Time) [What?!

传递给Date构造函数的Javascript日期字符串会给出奇怪的结果

创建新日期时,为什么我会在格式相同的日期字符串中得到不同的结果? CHROME (43.0.2357.134米)控制台: new Date('2014-12-25') Wed Dec 24 2014 17:00:00 GMT-0700 (Mountain Standard Time) [Chrome assumes Z with 00:00 (utc) and returns that local time] new Date('2014-1-25') Sat Jan 25 2014 00:00:00 GMT-0700 (Mountain Standard Time) [What?! exact same format (I thought) but

Inconsistencies when creating new date objects

I am creating new date objects in javascript and seeing some inconsistencies depending on whether I use the dateString parameter vs the year/month/day integer parameters. Here's an example: var dt1 = new Date(1979,3,5); var dt2 = new Date('1979-04-05'); jsFiddle with example dt1 is assigned the value: Thu Apr 05 1979 00:00:00 GMT-0500 (Central Daylight Time) dt2 is assigned the value:

创建新日期对象时的不一致

我正在JavaScript中创建新的日期对象,并根据我是否使用dateString参数与年/月/日整数参数看到一些不一致。 这是一个例子: var dt1 = new Date(1979,3,5); var dt2 = new Date('1979-04-05'); js以身作则 dt1分配值:Thu Apr 05 1979 00:00:00 GMT-0500(中央夏令时间) dt2分配值:Wed Apr 04 1979 19:00:00 GMT-0500(中央夏令时间) 有人可以解释这种行为吗? 第二个例子(dt2)恰好是Chrome从输入[type = date]

Javascript date +5 won't increment the month

I have the following code that does not want to properly add 5 days to a date. here is the code: // Grab previous session date so we can add 5 days and get new minDate var currdate = new Date(); var one_day=1000*60*60*24; var info = ''; var minDateBase = document.getElementById("class" + prevSession + "_date").value; var maxDateBase = document.getElementById("class1_date").value; var minDateBi

Javascript日期+5不会增加月份

我有以下代码不想正确添加5天到日期。 这里是代码: // Grab previous session date so we can add 5 days and get new minDate var currdate = new Date(); var one_day=1000*60*60*24; var info = ''; var minDateBase = document.getElementById("class" + prevSession + "_date").value; var maxDateBase = document.getElementById("class1_date").value; var minDateBits = minDateBase.split('-'); var maxDateBits = m

Confusion over noon versus midnight with date.js

I am using date.js in my project, and I am encountering something I didn't expect with respect to dates that had time components of exactly noon or exactly midnight. When I use the native javascript Date.parse method, I get the result I expected when parsing a date: // plain old javascript var date = new Date(Date.parse("10/21/2010 12:00:00 PM")); alert(date); I get this: Thu Oct 21 201

使用date.js在中午和午夜之间产生混乱

我在我的项目中使用了date.js,并且遇到了一些我没想到的事情,那些日期的时间组件恰好是中午或者正好是午夜。 当我使用本地javascript Date.parse方法时,我得到了我在分析日期时预期的结果: // plain old javascript var date = new Date(Date.parse("10/21/2010 12:00:00 PM")); alert(date); 我得到这个: Thu Oct 21 2010 12:00:00 GMT-0500(中央夏令时间) 我在2010年10月21日解释为中午,这是我认为我的输入日

Open a URL in a new tab (and not a new window) using JavaScript

I'm trying to open a URL in a new tab, as opposed to a popup window. I've seen related questions where the responses would look something like: window.open(url,'_blank'); window.open(url); But none of them worked for me, the browser still tried to open a popup window. Nothing an author can do can choose to open in a new tab instead of a new window. It is a user preference. CSS3 pr

使用JavaScript在新标签(而不是新窗口)中打开一个URL

我试图在新标签中打开一个URL,而不是一个弹出窗口。 我已经看到相关问题,其答案如下所示: window.open(url,'_blank'); window.open(url); 但是他们都没有为我工作,浏览器仍然试图打开一个弹出窗口。 作者没有办法可以选择在新选项卡中打开而不是在新窗口中打开。 这是用户偏好。 CSS3提出了新的目标,但规范已被放弃。 相反是不正确的。 通过在window.open的第三个参数中指定窗口的尺寸,当首选项是制表符时,可