JavaScript中自定义函数以及文本框、radio、下拉框的值的获取,结合淘宝竞拍案例来理解。。。

  1. 淘宝竞拍案例:

HTML部分代码:

<form action="#" method="post">
			<h2>欢迎进入淘宝竞拍</h2>
			<h3>本次拍卖品为:导盲犬</h3> 底价:
			<input type="text" id="Price" value="2000" /><br/><br/>
			 加价:
			<input type="text" id="AddPrice" /><br/>
			<span id="span2"></span><br/> 数量:
			<input type="text" id="num" /><br/>
			<span id="span3"></span><br/> 性别:
			<input type="radio" id="sex1" name="sex"  checked="checked"/>男
			<input type="radio" id="sex2" name="sex" />女<br/><br/> 付款方式:
			<select id="Pay1">
				<option>微信支付</option>
				<option>支付宝支付</option>
				<option>银联支付</option>
				<option>QQ支付</option>
				<option>刷卡支付</option>
			</select><br/>
			<span id="span1" ></span><br/> 总价:
			<input type="text" id="TotalPrice" /><br/><span id="span5" ></span><br/>
			<input type="button" value="确认" name="dj" onclick="Pay()" />
		</form>

  JavaScript部分代码:

 1     <script type="text/javascript">
 2             function Pay(){
 3                 var Price=2000;
 4                 var AddPrice = document.getElementById("AddPrice").value;
 5                 if(AddPrice=="")
 6                 {
 7                     document.getElementById("span2").innerHTML=‘<font color="red">亲,请输入加的价格哦</font>‘;
 8                 }
 9                 var num = document.getElementById("num").value;
10                 if(num=="")
11                 {
12                     document.getElementById("span3").innerHTML=‘<font color="red">亲,请输入您要拍的数量哦</font>‘;
13                 }
14                 var sex = sex1.checked ? ‘男‘ : ‘女‘;
15                  var totalMoney;
16                 var Pay1 = document.getElementById("Pay1");
17                 var index = Pay1.selectedIndex;
18                 switch(index) {
19                     case 0:
20                         document.getElementById("span1").innerHTML=‘<font color="red">微信支付打九折</font>‘;
21                         totalMoney = (parseInt(Price) + parseInt(AddPrice)) * parseInt(num)*0.9;
22                         break;
23                     case 1:
24                         document.getElementById("span1").innerHTML=‘<font color="red">支付宝支付打八折</font>‘;
25                         totalMoney = (parseInt(Price) + parseInt(AddPrice)) * parseInt(num)*0.8;
26                         break;
27                     case 2:
28                         document.getElementById("span1").innerHTML=‘<font color="red">银联支付打七折</font>‘;
29                         totalMoney = (parseInt(Price) + parseInt(AddPrice)) * parseInt(num)*0.7;
30                         break;
31                     case 3:
32                         document.getElementById("span1").innerHTML=‘<font color="red">QQ支付打九折</font>‘;
33                         totalMoney = (parseInt(Price) + parseInt(AddPrice)) * parseInt(num)*0.9;
34                         break;
35                     case 4:
36                         document.getElementById("span1").innerHTML=‘<font color="red">刷卡支付不打折</font>‘;
37                         totalMoney = (parseInt(Price) + parseInt(AddPrice)) * parseInt(num);
38                         break;
39                         default:document.getElementById("span1").innerHTML=‘<font color="red" >亲,支付方式可以进行选择的呦</font>‘;
40                 }
41               if(totalMoney==undefined)
42               {
43                   document.getElementById("span5").innerHTML=‘<font color=red>总价无法计算呦</font>‘;
44               }else
45               {
46                   document.getElementById("TotalPrice").value=totalMoney;
47               }
48
49             }
50
51         </script>

运行结果图:

原文地址:https://www.cnblogs.com/wjrelax/p/8921200.html

时间: 2024-08-05 15:36:42

JavaScript中自定义函数以及文本框、radio、下拉框的值的获取,结合淘宝竞拍案例来理解。。。的相关文章

通过jquery来实现文本框和下拉框动态添加效果,能根据自己的需求来自定义最多允许添加数量,实用的jquery动态添加文本框特效

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-

Jquery学习笔记:操作form表单元素之一(文本框和下拉框)

一.概述 在web页面开发中,经常需要获取和设置表单元素的值(如文本框中的内容),特别是在ajax应用中,更是常态.本文系统的介绍下如何操作. 同操作其它html元素一样,操作的过程差不多. 第一步,需要获取到表单元素对应的jquery(或dom)对象.这个主要是利用jquery的选择器机制. 第二步,调用表单元素的属性和方法来获取和设置值. 其中最常见的就是利用jquery对象的val方法.因为很多表单元素都有标准的 value属性,这个可以通过jquery的 val方法来读取和设置属性值.

robotframework自动化系列:文本类型的下拉框

对于下拉框定位和输入,这里主要遇到有两种类型的下拉选择. 其中一个类型是select-options格式,如图 这种方式的定位可以使用select from list by value或select from list by list或select from list等格式进行选择定位,具体可以参考随机下拉框定位选择. 而这里主要说的就是这种文本框类型的下拉选择,格式如图所示 此种文本框类型的下拉选择操作方法: 鼠标定位到设备此文本类型下拉框中 文本框中输入设备的首字母这里以0为例, 输入字母后

vue.js实现单选框、复选框和下拉框

Vue.js可以很方便的实现数据双向绑定,所以在处理表单,人机交互方面具有很大的优势.下边以单选框.复选框和下拉框为例介绍他们在HTML和Vue.js中的具体实现方式. 一.单选框 在传统的HTML中实现单选框的方法如下: <div id="app"> <input type="radio" name="gender" value="man" id="man"/><label

带复选框的下拉框

效果图: . css: <style type="text/css"> /* 带复选框的下拉框 */ ul li{ list-style: none; padding:0px; margin: 0px; } .select_checkBox{ border:0px solid red; position: relative; display:inline-block; } .chartQuota{ height:23px; float:left; display:inlin

Easyui-combobox-checkbox-带复选框的下拉框

$.post("getSubInsuranceTypeList.do",{parent_id:node.id},function(result){                        if (result.length == 0){                            $("#sub-insurance").addClass("none");                        } else {       

jsp页面刷新后保留文本输入框和下拉框的值

保留下拉框 <select name="status">     <option value="all" <c:if test="${status eq 'all'}">selected</c:if>>状态</option>     <option value="notstart" <c:if test="${status == 'notstar

文本框,下拉框,单选框只读状态属性

文本框只读属性:readonly="true" 下拉框只读属性: disabled="disabled" 单选框只读属性: $("#<%=txtIsReply.ClientID%>").click(function () { return false; })

JS-日期框、下拉框、全选复选框

<!-- 下拉框 --><link rel="stylesheet" href="static/ace/css/chosen.css" /> <!-- 日期框 --><link rel="stylesheet" href="static/ace/css/datepicker.css" /> <!-- 日期框 --> <script src="stati