您的位置:首页 > Web前端 > JavaScript

JS获取input标签的text值、JS获取下拉框内容、input控制只能输入数字等问题汇总

2014-06-11 19:38 941 查看

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">  


<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,'') " />
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: