最近在做框架的時(shí)候,需要加載.html文件和.json文件的時(shí)候出現(xiàn)了以下一個(gè)錯(cuò)誤:
這就讓我不得不想想是否是其他的原因了,后來,通過一番查詢,找到了原因。
原因如下:
Chrome不支持本地Ajax請求,當(dāng)我在.html文件中訪問.json文件時(shí)就會(huì)出現(xiàn)這個(gè)問題,就是說這個(gè)時(shí)候不能加載這個(gè).html文件。
打開Chrome快捷方式的屬性中設(shè)置:
右擊Chrome瀏覽器快捷方式,選擇“屬性”,
在“目標(biāo)”中加上 -allow-file-access-from-files,注意前面有個(gè)空格,
重啟Chrome瀏覽器便可。
這樣就正常加載了。
JQuery 實(shí)現(xiàn)自動(dòng)提示的文本框
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JQuery 實(shí)現(xiàn)自動(dòng)提示的文本框</title>
<style type="text/css">
<!--
body {
font-family: Arial;
font-size:12px;
padding:0px; margin:5px;
}
form {
padding:0px; margin:0px;
}
input {
font-family: Arial;font-size:12px;
padding:1px; margin:0px;
border: 1px solid #000000;
width: 200px;
}
#popup {
position:absolute;width: 202px;
color:#004a7e; font-family: Arial;font-size:12px;
left:41px; top:25px;
}
#popup.show {
border:1px solid #004a7e;
}
#popup.hide {
border:none;
}
ul{
list-style:none;
color:#004a7e;
padding:0px; margin:0px;
}
li.mouseOver{
background-color:#004a7e;
color:#FFFFFF;
}
li.mouseOut{
background-color:#FFFFFF;
color:#004a7e;
}
-->
</style>
<script src="../Jscript/jquery-1.4.2.js"></script>
<script type="text/javascript">
var inputField;
var popDiv;
var colorsUI;
function initVars(){
inputField = $("#colors");
popDiv = $("#popup");
colorsUI = $("#colors_ul");
}
function clearColors(){
colorsUI.empty();
popDiv.removeClass("show");
}
function setColors(the_colors){
clearColors();
popDiv.addClass("show");
for(var i = 0; i<the_colors.length; i++){
colorsUI.append($("<li>"+the_colors[i]+"<li>"));
colorsUI.find("li").click(function(){
inputField.val($(this).text());
clearColors();
}).hover(
function(){ $(this).addClass("mouseOver");},
function(){ $(this).removeClass("mouseOver");}
);
}
}
function findColors(){
initVars();
if(inputField.val().length > 0){
$.get("auto_prompt.jsp", {sColor:inputField.val()},
function(data){
var aResult = new Array();
if(data.length > 0 ){
aResult = data.split(",");
setColors(aResult);
}else{
clearColors();
}
});
}else{
clearColors();
}
}
</script>
</head>
<body>
<form method="post" name="myForm1">
Color: <input type="text" name="colors" id="colors" onkeyup="findColors();">
</form>
<div id="popup">
<ul id="colors_ul"></ul>
</div>
</body>
</html>
服務(wù)器端簡單jsp實(shí)現(xiàn)
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%@ page import="java.util.Date" %>
<title>Jquery ajax</title>
</head>
<body>
<%
//response.addHeader("pragma","no-cache");
String input = request.getParameter("sColor").trim();
if(input.length()==0)
return ;
String result="";
String [] aColors ={"a","and","as", "are","about","all", "adobe","an","account",
"b","be","bye","boy","business","back","because","before","book","below","been","blog","box"};
for(int i= 0 ; i<aColors.length; i++){
if(aColors[i].indexOf(input) == 0)
result+= aColors[i]+",";
}
if(result.length() > 0){
result = result.substring(0, result.length()-1);
}
response.getWriter().write(result);
response.getWriter().close();
%>
</body>
</html>
<SCRIPT> <!-- window.open ('page.html','newwindow','height=100,width=400,top=0,left=0,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no') //寫成一行 --> </SCRIPT> |
<SCRIPT LANGUAGE="javascript"> <!-- window.open ('page.html') --> </SCRIPT> |
<SCRIPT LANGUAGE="javascript"> <!-- window.open ('page.html', 'newwindow', 'height=100, width=400, top=0,left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no') //寫成一行 --> </SCRIPT> |
<html> <head> <script LANGUAGE="JavaScript"> <!-- function openwin() { window.open ("page.html", "newwindow", "height=100, width=400, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no") //寫成一行 } //--> </script> </head> <body onload="openwin()"> …任意的頁面內(nèi)容… </body> </html> |
<script LANGUAGE="JavaScript"> <!-- function openwin() { window.open ("page.html", "newwindow", "height=100, width=100, top=0,left=0,toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no") //寫成一行 window.open ("page2.html", "newwindow2", "height=100, width=100, top=100, left=100,toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no") //寫成一行 } //--> </script> |
<script language="javascript"> <!-- function openwin() {window.open("page.html","","width=200,height=200") } //--> </script> |
<script language="JavaScript"> function closeit() {setTimeout("self.close()",10000) //毫秒} </script> |
<FORM> <INPUT TYPE='BUTTON' VALUE='關(guān)閉' onClick='window.close()'> </FORM> |
<html> <head> <SCRIPT LANGUAGE="JavaScript"> function openwin() {OpenWindow=window.open("", "newwin", "height=250, width=250,toolbar=no,scrollbars="+scroll+",menubar=no"); //寫成一行 OpenWindow.document.write("<TITLE>例子</TITLE>") OpenWindow.document.write("<BODY BGCOLOR=#ffffff>") OpenWindow.document.write("<h1>Hello!</h1>") OpenWindow.document.write("New window opened!") OpenWindow.document.write("</BODY>") OpenWindow.document.write("</HTML>") OpenWindow.document.close()} </SCRIPT> </head> <body> <a href="#" onclick="openwin()">打開一個(gè)窗口</a> <input type="button" onclick="openwin()" value="打開窗口"> </body> </html> |
<script> function openwin() {window.open("page.html","","width=200,height=200")} function get_cookie(Name) {var search = Name + "=" var returnvalue = ""; if (document.cookie.length > 0) { offset = document.cookie.indexOf(search) if (offset != -1) { offset += search.length end = document.cookie.indexOf(";", offset); if (end == -1) end = document.cookie.length; returnvalue=unescape(document.cookie.substring(offset,end)) } } return returnvalue; } function loadpopup(){ if (get_cookie('popped')==''){ openwin() document.cookie="popped=yes" } } </script> |
function fxmultiply(a,b)
{
var f1 = String(a).split(“.”).length>1 ? String(a).split(“.”)[1].length : 0;
var f2 = String(b).split(“.”).length>1 ? String(b).split(“.”)[1].length : 0;
var aa = String(a).replace(/^0*|\./g,”);
var bb = String(b).replace(/^0*|\./g,”);
return Number(aa)*Number(bb)/Math.pow(10,f1+f2);
}
在頁面中調(diào)用fxmultiply這個(gè)方法就ok了!!,希望對你的問題有所幫助
var inputDate=var inputDate = document.getElementById("conveyDate").value.replace(/-/g,"/");
var expireDate=(從數(shù)據(jù)庫獲取的時(shí)間)
一開始以為這兩個(gè)可以比較了,但是最后發(fā)現(xiàn)有問題,
所以還是最好還是把它們轉(zhuǎn)化為Date對象。
var inputparse = new Date(Date.parse(inputDate));
var expireparse = new Date(Date.parse(expireDate));
這樣比較就沒有問題了。
日期對象也可用于比較兩個(gè)日期。
下面的代碼將當(dāng)前日期與 2008 年 8 月 9 日做了比較:
var myDate=new Date(); myDate.setFullYear(2008,7,9); var today = new Date(); if (myDate>today) { alert("Today is before 9th August 2008"); } else { alert("Today is after 9th August 2008"); }
? 這樣就可以實(shí)現(xiàn)不讓別人選擇自己的內(nèi)容。是不是挺簡單的!