当前位置:编程学习 > JS >>

Js for Select


1)var   obj;
obj = document.getElementById("Card"); //获取标签的Id
index = obj.selectedIndex; // 选中索引
value = obj.options[index].value; // 选中value值
text = obj.options[index].text; // 选中text值


2)增加新一行
addSelectEmptyAndValueOption(obj,value,text);
function addSelectEmptyAndValueOption(select,value,value2){
var option = document.createElement("option");
option.value = value;
option.innerHTML =value2;
select.appendChild(option);
 }
 
3)$('#selectId').empty();  //清空数据


4)省、市、区的联动,选择默认值
function refreshResult(s){
var obj;
var str;
var i;
if(s=="1"){
obj= document.getElementById("province");
  str='<%=deliveryprovince%>';
for(i=0;i<obj.length;i++){
             if(obj[i].text==str){
                  obj[i].selected=true;
                  showAreaInfo(obj[i].value,"city");
                  refreshResult("2");
                 }
}
 }else if(s=="2"){
obj= document.getElementById("city");
   str='<%=deliverycity%>';
for(i=0;i<obj.length;i++){
             if(obj[i].text==str){
                  obj[i].selected=true;
                  showAreaInfo(obj[i].value,"county");
                  refreshResult("3");
                 }
}
 }else if(s=="3"){
obj= document.getElementById("county");
   str='<%=deliveryarea%>';
for(i=0;i<obj.length;i++){
             if(obj[i].text==str){
                  obj[i].selected=true;
                 }
}


}
}


5)动态给table添加新一行的数据
function insertRow2(MaterialCode,MaterialName,Weight,UnitName,RetailPrice,InvQty,i){
var lb1Name="lbName"+i; //货品全称
var lb1Price="lbPrice"+i;//价格
var lbWeight="lbWeight"+i;       //规格
var lbInvQty="lbInvQty"+i;           //库存量
    $("#shopInvInfo").append("<tr>"+
    '<td width=100><label id='+lb1Name+'>'+MaterialName+'</label></td>'+
    '<td width=100>(<label id='+lbWeight+'>'+Weight+''+UnitName+'</label>)</td>'+
    '<td width=100>(<label id='+lb1Price+'>'+RetailPrice+'元</label>)</td>'+
    '<td width=100>备货量:<label id='+lbInvQty+'>'+InvQty+'</label></td>'+
    "</tr>");
}


作者:loveheronly
补充:web前端 , JavaScript ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,