㈠ javaScript 中一個函數有多個形參,當調用的時候可不可以只傳遞一個實參啊
當然可以,Javascript支持動態參數的,比如:
function abc(){
for(var i=0;i<arguments.length;i==){
alert(arguments[i]);
}
}
調用:
abc(1);
abc(1, "222", 443);
㈡ js怎樣動態調用外部CSS
<style>
body{ color:#FF0000}
a:hover{ background:#00ccFF}
</style>
<script language="javascript">
var indexcss=new Array()
indexcss[0]='index0.css'
indexcss[1]='index1.css'
indexcss[2]='index2.css'
function loadjscssfile(filename, filetype){
if (filetype=="css"){ //判斷文件類型
var fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet")
fileref.setAttribute("type", "text/css")
fileref.setAttribute("href", filename)
}
if (typeof fileref!="undefined")
document.getElementsByTagName("head")[0].appendChild(fileref)
}
document.getElementsByTagName("head")[0].appendChild(fileref)
</script>
<a href="#" onClick="loadjscssfile(indexcss[0],'css')">1111css</a>
<a href="#" onClick="loadjscssfile(indexcss[1],'css')">2222css</a>
<a href="#" onClick="loadjscssfile(indexcss[2],'css')">3333css</a>
㈢ 怎麼用js動態 設置select中的某個值為選中值
用JS動態設置select的方法如下:
手動通過原生JS來實現:
/**
* 設置select控制項選中
* @param selectId select的id值
* @param checkValue 選中option的值
*/
function set_select_checked(selectId, checkValue){
var select = document.getElementById(selectId);
for (var i = 0; i < select.options.length; i++){
if (select.options[i].value == checkValue){
select.options[i].selected = true;
break; } } }
然後通過這樣來調用:
// 設置select選中該班組
set_select_checked('edit-group', group_id);
注意:不要傳'#edit-group'。
(3)javascript動態調用函數擴展閱讀
js動態設置Select中Option選中
/** *設置select選中
*@paramselectIdselect的id值
*@paramcheckValue選中option的值
*@authorlqy */
functionsetSelectChecked(selectId,checkValue){
varselect=document.getElementById(selectId);
for(vari=0;i<select.options.length;i++){
if(select.options[i].innerHTML==checkValue){
select.options[i].selected=true;
break; } } };