Archives for the ‘javascript’ Category

动态嵌入 javascript 和 css

Tuesday, February 26th, 2008

动态嵌入 css 代码

var headID = document.getElementsByTagName(“head”)[0];
var cssNode = document.createElement(‘link’);
cssNode.type = ‘text/css’;
cssNode.rel = ’stylesheet’;
cssNode.href = ‘FireFox.css’;
cssNode.media = ’screen’;
headID.appendChild(cssNode);

动态嵌入 javascript 代码

var headID = document.getElementsByTagName(“head”)[0];
var newScript = document.createElement(’script’);
newScript.type = ‘text/javascript’;
newScript.src = ‘http://www.somedomain.com/somescript.js’;
headID.appendChild(newScript);

Ajax 就加入 javascript

function ajaxObject(url, callbackFunction) {

var that=this;

this.updating = false;

this.update = function(passData,postMethod) {

if (that.updating==true) { return false; }

that.updating=true;

var AJAX = null;

if (window.XMLHttpRequest) {

AJAX=new XMLHttpRequest();

} else {

AJAX=new ActiveXObject(“Microsoft.XMLHTTP”);

}

if (AJAX==null) {

return false;

} else {

AJAX.onreadystatechange = function() {

if (AJAX.readyState==4) {

that.updating=false;

that.callback(AJAX.responseText,AJAX.status,AJAX.responseXML);

delete AJAX;

}

}

var timestamp = new Date();

if (postMethod==’POST’) {

var uri=urlCall+’?'+timestamp.getTime();

AJAX.open(“POST”, uri, true);

AJAX.setRequestHeader(“Content-type”, “application/x-www-form-urlencoded”);

AJAX.send(passData);

} else {

var uri=urlCall+’?'+passData+’&timestamp=’+(timestamp*1);

AJAX.open(“GET”, uri, true);

AJAX.send(null);

}

return true;

}

}

var urlCall = url;

this.callback = callbackFunction || function () { };

}

function attachScript(responseText, responseStatus) {

// This function is called by the ajaxObject when the server has finished

// sending us the requested script.

if (responseStatus==200) {

eval(responseText);

}

}

// ajaxObject is an object constructor, pass it the server url you want it to call

// and the function name you want it to call when it gets the data back from the server.

// Use the .update() method to actually start the communication with the server.

// The first optional argument for update is the data you want to send to the server.

// ajaxvar.update(‘id=1234&greed=good&finish=true’);

// The second optional argument for update is ‘POST’ if you want to send the data

// as a POST instead of the default GET (post can handle larger amounts of data and

// the data doesn’t show up in your server logs).

// ajaxvar.update(‘id=1234&greed=good&finish=true’,'POST’);

var getScriptViaAjax=new ajaxObject(‘http://mydomain.com/somescript.js’,attachScript);

getScriptViaAjax.update();

var anotherScript = new ajaxObject(‘http://mydomain.com/anotherScript.php’,attachScript);

anotherScript.update(‘userId=4323′,’POST’);

flickr tag ajax 搜索

<script type=”text/javascript”>

function jsonFlickrFeed(feed){

z=”;

for (x=0; x<feed.items.length; x++) {

tmp=feed.items[x].media.m;

tmp=tmp.replace(/_m\.jpg/g,’_s.jpg’);

z+=’<img src=”‘+tmp+’” mce_src=”‘+tmp+’” alt=”some img” width=”75px” height=”75px” style=”margin: 2px;”>’;

}

document.getElementById(‘pics’).style.display=’block’;

document.getElementById(‘pics’).innerHTML=z;

}

function searchFlickr() {

var headID = document.getElementsByTagName(“head”)[0];

var newScript = document.createElement(’script’);

tagID = escape(document.getElementById(‘tags’).value);

document.getElementById(‘tags’).value=”;

newScript.type = ‘text/javascript’;

newScript.src = ‘http://flickr.com/services/feeds/photos_public.gne?tags=’ + tagID + ‘&format=json’;

headID.appendChild(newScript);

document.getElementById(‘pics’).style.display=’block’;

document.getElementById(‘pics’).innerHTML=”Loading…”;

return false;

}

</script>

<form action = “#” onsubmit=”return searchFlickr();”>

<input type=’text’ size=’40′ id=’tags’>   <input type=’submit’>

</form>

<div style=’border: 1px solid black; width: 100%; display: none;’ id=’pics’></div>

via http://www.hunlock.com/blogs/Howto_Dynamically_Insert_Javascript_And_CSS

10 个 javascript 滑动菜单效果及代码

Tuesday, October 16th, 2007

都是些不错的javascript 滑动菜单效果,还有源代码可供下载。

Deziner Folio

Moofx

Stickman Labs

Chris Esler

Aariadne

Artviper

Nyokiglitter

Portalzine

jQuery

Solutoire


点击这里打开新窗口浏览此网页

flash form

Thursday, October 11th, 2007

// ===============================================

// Augment TextField Class

// ===============================================

TextField.prototype.onKeyDown = function () {

if (Key.getCode() == Key.ENTER

&& this.pressedOnce == undefined

&& this.isFocused()) {

this.onSubmit();

this.pressedOnce = true;

}

};

TextField.prototype.onKeyUp = function () {

if (Key.getCode() == Key.ENTER) {

this.pressedOnce = undefined;

}

}

TextField.prototype.isFocused = function () {

if (Selection.getFocus() == targetPath(this)) {

return true;

}

return false;

};

// ===============================================

// Implement Form

// ===============================================

// Prepare the data transfer object.

var sender = new LoadVars();

// Activate Enter key for text fields.

username_txt.onSubmit = submitForm;

Key.addListener(username_txt);

password_txt.onSubmit = submitForm;

Key.addListener(password_txt);

// Set submit button handler.

submit_pb.setClickHandler(“submitForm”);

// Provide custom form submission function.

function submitForm () {

sender.user = username_txt.text;

sender.pass = password_txt.text;

sender.send(“http://www.somesite.com/cgi-bin/login.pl”, “_blank”, “GET”);

}

via http://www.oreillynet.com/pub/a/javascript/2003/05/20/colinmoock.html?page=2

flash xml 方法、属性

Friday, September 21st, 2007

flash 真变态,拿文字节点的时候还需要多走一次DOM。比如

hhh

这样的xml内容。用

myXML.firstChild.firstChild.firstChild.nodeName 可以得到 item

但要得到 hhh,则要再多写一个 firstChild!真变态,害我折腾了十几分钟

myXML.firstChild.firstChild.firstChild.firstChild.nodeValue

方法比javascript要少一些,但还够用,就是罗嗦一些。

appendChild(XMLNode.appendChild 方法),attributes(XMLNode.attributes 属性),childNodes(XMLNode.childNodes 属性),cloneNode(XMLNode.cloneNode 方法),firstChild(XMLNode.firstChild 属性),hasChildNodes(XMLNode.hasChildNodes 方法),insertBefore(XMLNode.insertBefore 方法),lastChild(XMLNode.lastChild 属性),nextSibling(XMLNode.nextSibling 属性),nodeName(XMLNode.nodeName 属性),nodeType(XMLNode.nodeType 属性),nodeValue(XMLNode.nodeValue 属性),parentNode(XMLNode.parentNode 属性),previousSibling(XMLNode.previousSibling 属性),removeNode(XMLNode.removeNode 方法),toString(XMLNode.toString 方法)

javascript 颜色选择器

Thursday, September 13th, 2007


点击这里打开新窗口浏览此网页

代码很干净,来自 http://blog.inlet-media.de/colorpicker/

定制自己的opera显示信息

Tuesday, September 11th, 2007

opera 地址栏,opera:config ,搜索 Language File,察看语言文件的地址。打开后可编辑。比如

-2061349988=”Welcome to Opera”

启动欢迎信息就可以改成

-2061349988=”欢迎使用郭爽的opera浏览器”

再比如修改

-1713924769=”Size”

显示更多

可以为 opera:cache 增加图片缩略图显示功能。