javascript_javascript スキルの解析における実践的な関数の使用方法の詳細な説明
function addBookMark(url, title){
//将网页添加到收藏addBookMark(window.location,document.title)
if(document.all){
window.external.addFavorite(url,title);
}else if (window.sidebar){
window.sidebar.addPanel(title,url,'');
}else{
alert('添加失败');
}
}
function setHomepage(obj,url) {
// setHome(this, window.location)
try {
obj.style.behavior = 'url(#default#homepage)';
obj.setHomePage(url);
} catch (e) {
if (window.netscape) {
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
} catch (e) {
alert('此操作被浏览器拒绝!\n请在浏览器地址栏输入"about:config"并回车
然后将 [signed.applets.codebase_principal_support]的值设置为"true",双击即可。');
}
var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
prefs.setCharPref('browser.startup.homepage', vrl);
}
}
}
function boxMove(box){
//可移动的层
var w = box.scrollWidth,h = box.scrollHeight;
var iWidth = document.documentElement.clientWidth;
var iHeight = document.documentElement.clientHeight;
var moveX = 0,moveY = 0,moveTop = 0,moveLeft = 0,moveable = false;
box.onmousedown = function(e){
moveable = true;
e = window.event?window.event:e;
moveX = e.clientX-box.offsetLeft;
moveY = e.clientY-box.offsetTop;
box.style.zIndex++;
}
document.onmousemove = function(e){
if(moveable){
e = window.event?window.event:e;
var x = e.clientX - moveX;
var y = e.clientY - moveY;
if ( x > 0 &&( x + w < iWidth) && y > 0 && (y + h < iHeight)){
box.style.left = x + "px";
box.style.top = y + "px";
box.style.margin = "auto";
}
}
}
document.onmouseup = function (){moveable = false;};
}
function getHtmlRoot(){
/*获得html文档的根元素*/
if(document.compatMode.toLowerCase()=="css1compat"){
htmlRoot = document.documentElement;
}else{
htmlRoot = document.body;
}
return htmlRoot;
}
function showWindow(boxId, closeId, showBg){//弹窗
htmlRoot = getHtmlRoot();
box = document.getElementById(boxId);
boxId = '#' + boxId;
closeId = '#' + closeId;
showBox = $(boxId);
showBox.show();
z_index = 20;
moveLeft = (htmlRoot.clientWidth- box.clientWidth)/2 + htmlRoot.scrollLeft +'px';
moveTop = (htmlRoot.clientHeight - box.clientHeight)/2 + htmlRoot.scrollTop;+'px';
showBox.css({position:'absolute', left:moveLeft,zIndex:z_index, top:moveTop});
boxMove(box);
if(showBg){
objMask = document.createElement("div");
objMask.className = "BoxMask";
htmlRoot.appendChild(objMask);
objMask.style.cssText += 'position:absolute;top:0; left:0;filter:Alpha(Opacity=50);opacity:0.5;background:#AAA;';
objMask.style.zIndex = z_index -1;
objMask.style.width = htmlRoot.clientWidth + 'px';
objMask.style.height = htmlRoot.scrollHeight + htmlRoot.scrollTop + 'px';
}
$(closeId).click(function(){
showBox.hide();
mybg.style.display = "none";
});
$('.closeBtn').click = function(){
showBox.hide();
mybg.style.display = "none";
};
}
function getFormQuery(formId){
/*生成查询字串*/
formObj = document.getElementById(formId);
var i, queryString = "", and = "", itemValue;
for(i = 0; i
if ( item.name!='' ){
if(item.type == 'select-one'){
itemValue = item.options[item.selectedIndex].value;
}else if ( item.type=='checkbox' || item.type=='radio'){
if ( item.checked == false ){ continue; }
itemValue = item.value;
}else if ( item.type == 'button' || item.type == 'submit' || item.type == 'reset' || item.type == 'image'){
continue;
}else{
itemValue = item.value;
}
// itemValue = escape(itemValue);
queryString += and + item.name + '=' + itemValue;
and="&";
//queryString += and + encodeURIComponent(item.name) + '=' +encodeURIComponent( itemValue);
}
}
return queryString;
}
//定义js错误处理函数
onerror = errHandle;
function errHandle(msg,url,line){
var txt=""
txt = "本页中有错误!
\n"
txt += "错误: "+ msg +"\n"
txt += "地址: " + url + "\n"
txt += "行数: " + line + "\n\n"
alert(txt);
return false;
}
function setAutoWidth(id,width,size){
//最小或最大宽度
var obj = document.getElementById(id);
if(size=='max'){
obj.style.width = (obj.clientWidth > width) ? width + "px" : "auto";
}else{
obj.style.width = (obj.clientWidth < width) ? width + "px" : "auto";
}
}
function fontScroll(id){
/*向左滚动的文字 */
var obj = document.getElementById(id);
var text = obj.innerHTML;
var first = text.charAt(0);
var left = text.substring(1, text.length);
obj.inerHTML = left + first;
//这个写函数之外 setInterval('fontScroll(id)', 500);
}
function bubbleSort(arr){
/*Bubble sort method*/
var sign = false // Initialize the transposition sign to false
for(var i=0; i < arr. length-1; i ){
for(varj=0; j < arr.length-1-i; j ){
if(arr[j]> arr[j 1]){
vartemp = arr[j]
arr[j]= arr[j 1]
arr[j 1]= temp
sign= true // If there is a transposition in the current circle comparison , then the substitution mark is true
}
}
if(sign)// Determine whether there has been a substitution in the current circle...
sign= false // If there has been a substitution, retry The replacement bit is marked as false
else
break// If not, terminate
}
return arr;
}
function getCoordinate(evt){
/*Get the coordinates of the cursor*/
var x = evt.clientX;
var y = evt.clientY;
document.getElementById('show' ).innerHTML = x ' &' y;
}
function checkEmail(email){
/*Detect multiple email formats separated by semicolons (;)*/
if(email != null){
if(email.indexOf(" ;",0) == -1){ //indexOf(searched, starting position) returns the position where a certain string first appears in the source string. If it fails, -1
is returned if(!isEmail(email )){
alert("The format of the single email is incorrect, please re-enter!"); > }else{
var emailArr = email.split(";");//split (separated segment, total length of array) string is divided into string array
var i, iMax = emailArr.length;
for(i = 0; i < iMax; i ){
if(emailArr[i] != null || emailArr != ""){
if(!isEmail(emailArr[i]) ){
alert("One of the multiple email formats is incorrect, please check again before entering!");
document.getElementById("email").focus();
return false ;
}
}
}
}
}
}
function isEmail(str){
var reg = /^(w) (.w )*@(w) ((.w ) )$/;
return reg.test(str);//test (tested string) detects whether a string matches a certain pattern.
}
}

ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

メモ帳++7.3.1
使いやすく無料のコードエディター

SublimeText3 中国語版
中国語版、とても使いやすい

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

ドリームウィーバー CS6
ビジュアル Web 開発ツール

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

ホットトピック









Go 言語は、クロージャとリフレクションという 2 つの動的関数作成テクノロジを提供します。クロージャを使用すると、クロージャ スコープ内の変数にアクセスでき、リフレクションでは FuncOf 関数を使用して新しい関数を作成できます。これらのテクノロジーは、HTTP ルーターのカスタマイズ、高度にカスタマイズ可能なシステムの実装、プラグイン可能なコンポーネントの構築に役立ちます。

C++ 関数の名前付けでは、読みやすさを向上させ、エラーを減らし、リファクタリングを容易にするために、パラメーターの順序を考慮することが重要です。一般的なパラメータの順序規則には、アクション-オブジェクト、オブジェクト-アクション、意味論的な意味、および標準ライブラリへの準拠が含まれます。最適な順序は、関数の目的、パラメーターの種類、潜在的な混乱、および言語規約によって異なります。

効率的で保守しやすい Java 関数を作成するための鍵は、シンプルに保つことです。意味のある名前を付けてください。特殊な状況に対処します。適切な可視性を使用してください。

1. SUM 関数は、列またはセルのグループ内の数値を合計するために使用されます (例: =SUM(A1:J10))。 2. AVERAGE 関数は、列またはセルのグループ内の数値の平均を計算するために使用されます (例: =AVERAGE(A1:A10))。 3. COUNT 関数。列またはセルのグループ内の数値またはテキストの数をカウントするために使用されます。例: =COUNT(A1:A10)。 4. IF 関数。指定された条件に基づいて論理的な判断を行い、結果を返すために使用されます。対応する結果。

C++ 関数のデフォルト パラメーターの利点には、呼び出しの簡素化、可読性の向上、エラーの回避などがあります。欠点は、柔軟性が限られていることと、名前の制限があることです。可変引数パラメーターの利点には、無制限の柔軟性と動的バインディングが含まれます。欠点としては、複雑さの増大、暗黙的な型変換、デバッグの難しさなどが挙げられます。

C++ で参照型を返す関数の利点は次のとおりです。 パフォーマンスの向上: 参照による受け渡しによりオブジェクトのコピーが回避され、メモリと時間が節約されます。直接変更: 呼び出し元は、返された参照オブジェクトを再割り当てせずに直接変更できます。コードの簡素化: 参照渡しによりコードが簡素化され、追加の代入操作は必要ありません。

カスタム PHP 関数と定義済み関数の違いは次のとおりです。 スコープ: カスタム関数はその定義のスコープに限定されますが、事前定義関数はスクリプト全体からアクセスできます。定義方法: カスタム関数は function キーワードを使用して定義されますが、事前定義関数は PHP カーネルによって定義されます。パラメータの受け渡し: カスタム関数はパラメータを受け取りますが、事前定義された関数はパラメータを必要としない場合があります。拡張性: カスタム関数は必要に応じて作成できますが、事前定義された関数は組み込みで変更できません。

C++ の例外処理は、特定のエラー メッセージ、コンテキスト情報を提供し、エラーの種類に基づいてカスタム アクションを実行するカスタム例外クラスを通じて強化できます。 std::Exception から継承した例外クラスを定義して、特定のエラー情報を提供します。カスタム例外をスローするには、throw キーワードを使用します。 try-catch ブロックでdynamic_castを使用して、キャッチされた例外をカスタム例外タイプに変換します。実際の場合、open_file 関数は FileNotFoundException 例外をスローします。例外をキャッチして処理すると、より具体的なエラー メッセージが表示されます。
