javascript µÄlastIndexOf
½üÈÕÊÕ¼¯ÉÏÍòÐдúÂ룬ÕûÀíһЩ³öÀ´¡£
//V8ÒýÇæµÄʵÏÖ
function ToInteger( n ) {
n = Number( n );
var sign = ( n < 0 ) ? -1 : 1;
if ( n != n ) {
return 0;
}
if ( Math.abs( n ) == 0 || Math.abs( n ) == Number.POSITIVE_INFINITY ) {
return n;
}
return ( sign * Math.floor(Math.abs(n)) );
};
function lastIndexOf= (array,element, index) {
var length = array.length;
if (index == null) {
index = length - 1;
} else {
index = ToInteger(index);
// If index is negative, index from end of the array.
if (index < 0) index = length + index;
// If index is still negative, do not search the array.
if (index < 0) index = -1;
else if (index >= length) index = length - 1;
}
// Lookup through the array.
for (var i = index; i >= 0; i--) {
var current = array[i];
if ((current !== undefined) || i in this) {
if (current === element) return i;
}
}
return -1;
}
Ò»¸öÖØ´óµÄÎóÇøÊÇÒÔΪÔÉúAPI¶¼ÓÃCÓïÑÔʵÏÖ£¬Æäʵ²»È»£¬±ÈÈç»ðºüÓëchromeµÈÒÔËÙ¶ÈÖø³ÆµÄä¯ÀÀÆ÷£¬»ù±¾µÄ²¿·ÖÓÃCÓïÑÔʵÏÖºó£¬ÆäËûÇë¸ßÊָ㶨¡£±Ï¾¹ÓÃÆäËûÓïÑÔÀ´Ä£ÄâjavascriptºÜÈÝÒ×·¸´í£¬±ÈÈçIE6¡£ÍüÁË£¬ÄǶ«Î÷ÊǽÐJScript¡£
//Base2µÄʵÏÖ
function lastIndexOf(array, item, fromIndex) {
var length = array.length;
if (fromIndex == null) {
fromIndex = length - 1;
} else if (fromIndex < 0) {
fromIndex = Math.max(0, length + fromIndex);
}
for (var i = fromIndex; i >= 0; i--) {
if (array[i] === item) return i;
}
return -1;
}
//Prototype1.61µÄʵÏÖ
function lastIndexOf(array,item, i) {
i = isNaN(i) ? array.length : (i < 0 ? array.length + i : i) + 1;
var n = array.slice(0, i).reverse().indexOf(item);
return (n < 0) ? n : i - n - 1;
Ïà¹ØÎĵµ£º
1¡¢Êý×éµÄ´´½¨
var arrayObj = new Array();¡¡//´´½¨Ò»¸öÊý×é
var arrayObj = new Array([size]);¡¡//´´½¨Ò»¸öÊý×é²¢Ö¸¶¨³¤¶È£¬×¢Òâ²»ÊÇÉÏÏÞ£¬Êdz¤¶È
var arrayObj = new Array([element0[, element1[, ...[, elementN]]]]);¡¡´´½¨Ò»¸öÊý×é²¢¸³Öµ
Ҫ˵Ã÷µÄÊÇ£¬ËäÈ»µÚ¶þÖÖ·½·¨´´½¨Êý×éÖ¸¶¨Á˳¤¶È£¬µ«Êµ¼ÊÉÏËùÓ ......
Javascript½âÒÉ
1. HTML¿ò¼ÜframesetµÄÓ¦ÓÃ
¿ò¼Ü±à³Ì¸ÅÊöÒ»¸öHTMLÒ³Ãæ¿ÉÒÔÓÐÒ»¸ö»ò¶à¸ö×Ó¿ò¼Ü£¬ÕâЩ×Ó¿ò¼ÜÒÔ<iframe>À´±ê¼Ç£¬ÓÃÀ´ÏÔʾһ¸ö¶ÀÁ¢µÄHTMLÒ³Ãæ¡£ÕâÀïËù½²µÄ¿ò¼Ü±à³Ì°üÀ¨¿ò¼ÜµÄ×ÔÎÒ¿ØÖÆÒÔ¼°¿ò¼ÜÖ®¼äµÄ»¥Ïà·ÃÎÊ£¬ÀýÈç´ÓÒ»¸ö¿ò¼ÜÖÐÒýÓÃÁíÒ»¸ö¿ò¼ÜÖеÄJavaScript± ......
ÓÃJavascriptÈ¡floatÐÍСÊýµãºóÁ½Î»£¬Àý22.127456È¡³É22.13,ÈçºÎ×ö£¿
1. ×µÄ°ì·¨....... [ÎÒ¾ÍÔõô¸ÉµÄ.........]
function get()
{
var s = 22.127456 + "";
var str = s.substring(0,s.indexOf(".") + 3);
alert(str);
}
2. ÕýÔò±í´ïʽЧ¹ ......
´úÂëÈëÏÂ:
<script language="JavaScript">
function getMyName(){
var myName="<%=session.getAttribute("MYNAME")%>";
alert(myName);
}
</script>
JavaScript´æsessionµÄÖµ:
´ÓÀíÂÛÉÏÀ´ËµJavaScriptÔÚÒ³Ãæ,¶ø´æsessionÔÚ·þÎñÆ÷¶Ë..ºÜÄÑÍê³É,µ«ÊÇÄã¿É ......
·½·¨Ò»¡¢
NPN_GetURL(m_Instance, "javascript:test()", NULL);
·½·¨¶þ¡¢
NPVariant rval;
NPN_InvokeDefault(m_Npp, objectDisconnect ,NULL, 0,&rval);
NPN_ReleaseVariantValue(&rval);
ÒÔÏÂÊÇjavascript
<script type="text/javascript">
&nb ......