JS獲取input標籤的text值、JS獲取下拉框內容、input控制只能輸入數字等問題彙總


1、在js中如何獲取input標籤的text值

var cgsl = document.getElementsByName("cgsl")[0].value; 
jsp源碼爲:

 <span>	</span><tr>
<span>		</span><td width="20%" align="right" bgcolor="#F2F8FF"><span class="font">採購數量:</span></td>
                <td width="30%" align="left" bgcolor="#F2F8FF" >  <html:text property="cgsl" maxlength="25" />
<span>		</span><font color="red"> *</font></td>
        </tr>

或者:

<input type="text" name="cgsl" maxlength="20" value="">

2、js獲取下拉框選擇的內容

var objSelect = document.all.hcjbxxid;
var hcjbxxid = objSelect[objSelect.selectedIndex].value;

對應jsp代碼:

               <td width="15%" height="50" align="right" bgcolor="#f1f9ff"><span class="font">耗材名稱:</span></td>
               <td width="80%" align="left" bgcolor="#f1f9ff"  colspan="3"> <html:select property="hcjbxxid" >
               <html:optionsCollection  name="datalist_1" label="hcmc" value="hcjbxxid"/>
               </html:select></td>
或者:

<select name="hcjbxxid">
<option value="4028ceeb461d259001461d26135d0001">水筆1</option>
<option value="4028ceeb461c8cfb01461c9b84410002">墨盒</option>
<option value="4028ceeb464278260146427910210002">電池</option>
<option value="4028ceeb464276f80146427758210002">鍵盤</option>
<option value="4028ceeb464276f801464277e8770004">膠帶</option>
<option value="4028ceeb4642810001464281feff0002">鼠標</option>
</select>

3、如何動態獲取下拉框內容(點A下拉框後B下拉框內容隨着改變)

function hcdlChange()
		{	
			var objSelect = document.all.hcdl;
			var hcdl = objSelect[objSelect.selectedIndex].value;
			document.forms[0].action="hcsgsq.do?method=addHcxx&hcdl="+hcdl;
			document.forms[0].submit();
		}

對應jsp代碼爲:

 <tr> 
    <td width="20%" height="25" align="right" bgcolor="#F2F8FF"><span class="font">耗材分類:</span></td>
    <td width="30%" align="left" bgcolor="#F2F8FF">  
    <html:select property="hcdl" style="width:157" onchange="hcdlChange()">
    <commoncode:getCodeList codeTypeId="1024" selectValue="<%=tmHcsqxxForm.getHcdl() %>"  /></html:select></td>
    <td width="15%" height="50" align="right" bgcolor="#f1f9ff"><span class="font">耗材名稱:</span></td>
    <td width="80%" align="left" bgcolor="#f1f9ff"  colspan="3"> <html:select property="hcjbxxid" >
    <html:optionsCollection  name="datalist_1" label="hcmc" value="hcjbxxid"/>
     </html:select></td>          
 </tr>

或者:

<pre name="code" class="html"><pre name="code" class="html"><tr>
<td width="20%" height="25" align="right" bgcolor="#F2F8FF"><span class="font">耗材分類:</span></td>
<td width="30%" align="left" bgcolor="#F2F8FF">&nbsp;&nbsp;

<select name="hcdl" onchange="hcdlChange()" style="width:157">

<option value="10241001">辦公耗材</option>
<option value="10241002">業務耗材</option>
<option value="10241003">基建工程</option>
<option value="10241004">辦公設備維修類</option>
<option value="10241005">業務設備維修類</option>
</select>
<pre name="code" class="html" style="font-size: 14px; font-weight: bold; line-height: 26px;"></td>
</pre><pre name="code" class="html" style="font-size: 14px; font-weight: bold; line-height: 26px;"><pre name="code" class="html"><td width="15%" height="50" align="right" bgcolor="#f1f9ff"><span class="font">耗材名稱:</span></td>
<td width="80%" align="left" bgcolor="#f1f9ff" colspan="3"> 
<select name="hcjbxxid">
<option value="4028ceeb461d259001461d26135d0001">水筆1</option>
<option value="4028ceeb461c8cfb01461c9b84410002">墨盒</option>
<option value="4028ceeb464278260146427910210002">電池</option>
<option value="4028ceeb464276f80146427758210002">鍵盤</option>
<option value="4028ceeb464276f801464277e8770004">膠帶</option>
<option value="4028ceeb4642810001464281feff0002">鼠標</option>
</select>
</td>
</tr>




4、Struts中的html:text實現input只能輸入數字

<html:text property="age" style="width:98%" onkeyup="value=value.replace(/[^\d]/g,'') " /> 




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章