---
title: "下拉列表默认选中"
author: "ITCheng"
date: "2012-09-11T16:41:18Z"
tags: []
categories: ["Web前端"]
slug: "untitled"
draft: false
lastmod: "2012-09-11T16:42:58Z"
id: 1675990
url: "https://itcheng.iteye.com/blog/1675990"
---

&lt;select id="sel" name="proSecond.profirsttype.profirstid"&gt;  
               &lt;c:forEach var="list" items="${listFirst}"&gt;  
               &lt;option value="${list.profirstid}"&gt;&lt;c:out value="${list.typename }"&gt;&lt;/c:out&gt; &lt;/option&gt;  
               &lt;/c:forEach&gt;  
              &lt;/select&gt;  
              &lt;script&gt;  
              function setSelectByValue(  
                domSelect,  
                strVal) {  
               var opts = domSelect.options;  
               for ( var i = 0, j = opts.length; i &lt; j; i++)  
                if (opts\[i].value === strVal)  
                 return domSelect.selectedIndex = i;  
              }  
              setSelectByValue(  
                document  
                  .getElementById('sel'),  
                '${proSecond.profirsttype.profirstid}');  
              &lt;/script&gt;