㈠ 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; } } };