input 取值,并计算,_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 12:25:02
Original
1256 people have browsed it

本帖最后由 erbao_vip 于 2013-11-06 13:14:13 编辑

html  jsp

我的input:
<td>						${g.newPrice}<input type="hidden" class="oneprice" value="${g.newPrice}">						</td>						<td><input type="button" value=" - "							size="3" class="l_i" id="lost"> 														 <input value="1"							size="2" id="number" maxlength="2" name="buynumbers"							class="number"							onkeyup="this.value=this.value.replace(/[^\d]/g,'') "> 																												<input type="button" value=" + " size="3" id="add" class="a_i">													</td>						<td><input value="${g.newPrice}"							id="all" class="all" name="totalprice_one" readonly="readonly"							disabled="disabled"></td>						<td>
Copy after login
Copy after login


jsp页面显示:
我想点击+,-按钮,改变数量,并改变小计的值,一个容易实现,但是多个怎么实现?看图,


回复讨论(解决方案)

我的input:

<td>						${g.newPrice}<input type="hidden" class="oneprice" value="${g.newPrice}">						</td>						<td><input type="button" value=" - "							size="3" class="l_i" id="lost"> 														 <input value="1"							size="2" id="number" maxlength="2" name="buynumbers"							class="number"							onkeyup="this.value=this.value.replace(/[^\d]/g,'') "> 																												<input type="button" value=" + " size="3" id="add" class="a_i">													</td>						<td><input value="${g.newPrice}"							id="all" class="all" name="totalprice_one" readonly="readonly"							disabled="disabled"></td>						<td>
Copy after login
Copy after login


jsp页面显示:
我想点击+,-按钮,改变数量,并改变小计的值,一个容易实现,但是多个怎么实现?看图, 一个怎么实现的,多个就怎么实现,贴出你一个实现的代码

你可以这样做,在打印的时候每一行给出一个id
那么第一行可以是0,那么第一行的输入框的id为 input_0
写一个方法

<table>			<tr>				<td>					<input type="button" value="+" onclick="show_num('input_0',this)"/>				</td>				<td>					<input type="text" value="1" id="input_0"/>				</td>				<td>					<input type="button" value="-" onclick="show_num('input_0',this)"/>				</td>			</tr>			<tr>				<td>					<input type="button" value="+" onclick="show_num('input_1',this)"/>				</td>				<td>					<input type="text" value="1" id="input_1"/>				</td>				<td>					<input type="button" value="-" onclick="show_num('input_1',this)"/>				</td>			</tr>			<tr>				<td>					<input type="button" value="+" onclick="show_num('input_2',this)"/>				</td>				<td>					<input type="text" value="1" id="input_2"/>				</td>				<td>					<input type="button" value="-" onclick="show_num('input_2',this)"/>				</td>			</tr>		</table>function show_num(input_id,item){				var target=document.getElementById(input_id);				var sign=item.value;				console.log(sign);				var val=parseInt(target.value);				if(sign=="+"){					val=val+1;				}else{					val=(val-1)>0?(val-1):0;				}				target.value=val;			}
Copy after login


代码:以前是用Id取值的,现在改为用class取值:

if ($("#number").val() == 1) {		$("#lost").attr("disabled", "disabled");	}	$("#add").click(function() {		var n = $("#number").val();		n = n - 0 + 1;		// alert(n);		if (n > 0) {			// .attr("disabled",false); //disabled="disabled"			$("#lost").attr("disabled", false);		}		$("#number").val(n);		$("#all").val($("#oneprice").val() * n);	});	$("#lost").click(function() {		var n = $("#number").val();		n = n - 1;		// alert(n);		if (n == 1 || n == 0) {			// .attr("disabled",false); //disabled="disabled"			$("#lost").attr("disabled", "disabled");		}		$("#number").val(n);		$("#all").val($("#oneprice").val() * n);	});	// keyup	$("#number").keyup(function() {		n = $("#number").val();		if (n <= 0) {			// $("#lost").attr("disabled", "disabled");			$("#number").val(1);			$("#all").val($("#oneprice").val());		}		if (n > 0) {			$("#lost").attr("disabled", false);			$("#all").val($("#oneprice").val() * n);		}	});
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!