一個關於js函數的傳值問題


以前對調用js函數的固有理解:

<input type="button" value="選擇1" onclick="depQuery1('第一個參數','第二個參數')" />

function depQuery1(field1, field2,path) {
    alert(field1);
    alert(field2);
}

要調用js函數depQuery1函數,就必須要傳一個給定的值,像是上面的情況,其實不是這樣的...也可以這樣傳值

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML> <HEAD> <TITLE> New Document </TITLE> 
<script>
//這是一個js的函數
function depQuery(field1, field2, path) {
    
    alert(field1.value);
    alert(field2.value);
    
}

function depQuery1(field1, field2,path) {
    
    alert(field1);
    alert(field2);
    
}
</script>
</HEAD>
<BODY>
<input type="text" id="parentDepx" name="parentDepName" value="這是默認值" />
<input type="hidden" id="pdepIdx" name="dep.pdepId" value="這是隱藏域中的id值0121021" />

<!-- 
   當單擊下面的  選擇  按鈕時,會調用depQuery(pdepId,parentDep)函數
   這里的pdepId是文本框的id,parentDep是隱藏域的id,會把對應的值傳到depQuery函數中
-->
<input type="button" value="選擇" onclick="depQuery(pdepIdx,parentDepx);" />
<input type="button" value="選擇1" onclick="depQuery1('第一個參數','第二個參數')" />
</BODY> 
</HTML>

心中的滋味只有知道...

 歡迎轉載,轉載時請注明出處http://www.cnblogs.com/wanggd

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM