项目前端技术总结

获取select ,radio表单选中的值

$("input[type='radio']:checked").val()

 $("#s option:selected").text();  //获取选中的option的文本值

获取select中option的被选中的value值:

           $("#s").val();

           $("#s option:selected").val();

js获取select选中的值:

          var sel=document.getElementById("select1"); 

          var index = sel.selectedIndex; // 选中索引

          albumid= sel.options[index].value;//要的值



动态增加select表单的option

1.构造对象的方法:(siteList是select的id)

var option=new Option(site.siteName,site.id)

$("#siteList")[0].options.add(option) */

2.增加dom元素的方法:

$("#siteList").append('<option >'+site.siteName+'</option>')

猜你喜欢

转载自blog.csdn.net/fanxin_i/article/details/80911185