首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

javascript 函数,希望下午能结帐。///////////没学过javascript真郁闷

2012-03-26 
求一个 javascript 函数,希望下午能结帐。///////////没学过javascript真郁闷。商品XX名: inputid TextBo

求一个 javascript 函数,希望下午能结帐。///////////没学过javascript真郁闷。
商品XX名: <input   id= "TextBox_1 "   name= "TextBox_1 "   type= "text "   runat= "server "   /> <br   />
                商品XX名: <input   id= "TextBox_2 "   name= "TextBox_2 "   type= "text "   runat= "server "   /> <br   />
                商品XX名: <input   id= "TextBox_a "   name= "TextBox_3 "   type= "text "   runat= "server "   /> </div>
                很多input......... <br   />
                <br   />
                <br   />
                <br   />
                产品价格: <input   id= "金额 "   name= "金额 "   type= "text "   runat= "server "   style= "width:   49px "   /> 元  
                <input   id= "商品1 "   type= "button "   value= "商品1 "     onclick= "JSfunction( '1 ', 'b ', '6 ') "   />
                <input   id= "商品2 "   type= "button "   value= "商品2 "   onclick= "JSfunction( '4 ', '5 ', 'c ') "   />
  ========================================================================              
               
              当在   [金额]   里输入金额后点   [商品]   按钮,那么就把输入的金额复制到   TextBox_X   的输入框
             
             
              比如我在   [金额]   填入   100,   再点击   [商品1]   按钮,那么页面上的   TextBox_1,TextBox_b,TextBox_6   的输入框都自动填入100,并把这几个输入框的背景色变为黄色。
               
               
               
                注:
                        前提条件:[金额]   输入框里只能输入   5-200   元
                       
                       
                        JSfunction( '1 ', 'b ', '6 ')
                        TextBox_1,TextBox_b,TextBox_6   , <---input输入框命名规则是前面加了   TextBox_

[解决办法]
TextBox_1,TextBox_b,TextBox_6的名称是固定的吗?还是自动生成的?
如果是死的,那就写个没有参数的函数就可以
不然就传3个控件进去
[解决办法]
function JSfunction(a,b,c)
{
money = document.getElementById( '金额 ').value;
document.getElementById( 'TextBox_ '+a).value = money;


document.getElementById( 'TextBox_ '+b).value = money;
document.getElementById( 'TextBox_ '+c).value = money;
}

手写没测
[解决办法]
如楼上,再在函数里控制一下三个控件的样式,就OK了
[解决办法]
function JSfunction(a,b,c)
{
money = document.getElementById( '金额 ').value;
//要进行数字验证
if(money <5||money> 200)
{
alert( "Error!Must between 5-200 ");
return false;
}
tbx = document.getElementById( 'TextBox_ '+a);
tbx.value = money;
tbx.style.backgroundColor= 'yellow ';

tbx = document.getElementById( 'TextBox_ '+b);
tbx.value = money;
tbx.style.backgroundColor= 'yellow ';

tbx = document.getElementById( 'TextBox_ '+c);
tbx.value = money;
tbx.style.backgroundColor= 'yellow ';
}
[解决办法]
這要求很簡單呀,你把整個html代碼貼出來,我來幫你改。
[解决办法]
对头
加样式,也跟赋值类似,把value改成style.bgcolor之类的
[解决办法]
function JSfunction(t1,t2,t3)
{

t1.value = document.getElementById( "金额 ").value;
t1.style.backgroundColor = "yellow ";
t2.value = document.getElementById( "金额 ").value;
t2.style.backgroundColor = "yellow ";
t3.value = document.getElementById( "金额 ").value;
t3.style.backgroundColor = "yellow ";
}

注意调用
<input id= "商品1 " type= "button " value= "商品1 " onclick= "JSfunction(TextBox_1,TextBox_2,TextBox_a) " /> 没有 ' '
[解决办法]
if (document.getElementById( "金额 ").value> 200 || document.getElementById( "金额 ").value <5)
{
alert( '金额范围为5-200 ');
return false;
}

这个加上是判断的
[解决办法]
if(document.getElementById( '金额 ').value..match(/[^\d]/g)==null && parseInt(document.getElementById( '金额 ').value)> =5 && parseInt(document.getElementById( '金额 ').value) <=200)

补充个判断


[解决办法]
慢写,别急,上面的差不多了。
[解决办法]
//基本代码
<script type= "text/javascript ">
function JSfunction(a, b, c)
{
var temp = document.getElementsByTagName( "input ")
for(var i = 0; i < temp.length; i++)
{
if(temp[i].type == "text " )
{
if((temp[i].id == "TextBox_ " + a) || (temp[i].id == "TextBox_ " + b) || (temp[i].id == "TextBox_ " + c))
temp[i].value = document.Form1.je.value;
}
}
}
</script>
[解决办法]
up
[解决办法]
<HTML>
<HEAD>
<title> WebForm1 </title>
<script type= "text/javascript ">


function JSfunction(a, b, c)
{
if (document.getElementById( "je ").value> 200 || document.getElementById( "je ").value <5)
{
alert( '金额范围为5-200 ');
return false;
}

var temp = document.getElementsByTagName( "input ")
for(var i = 0; i < temp.length; i++)
{
if(temp[i].type == "text " )
{
if((temp[i].id == "TextBox_ " + a) || (temp[i].id == "TextBox_ " + b) || (temp[i].id == "TextBox_ " + c))
{
temp[i].value = document.Form1.je.value;
temp[i].style.backgroundColor = "yellow ";
}
}
}
}
</script>
</HEAD>
<body>
<form id= "Form1 " method= "post " runat= "server ">
商品XX名: <input id= "TextBox_1 " name= "TextBox_1 " type= "text " runat= "server "> <br>
商品XX名: <input id= "TextBox_2 " name= "TextBox_2 " type= "text " runat= "server "> <br>
商品XX名: <input id= "TextBox_3 " name= "TextBox_3 " type= "text " runat= "server "> <br>
商品XX名: <input id= "TextBox_4 " name= "TextBox_1 " type= "text " runat= "server "> <br>
商品XX名: <input id= "TextBox_5 " name= "TextBox_2 " type= "text " runat= "server "> <br>
商品XX名: <input id= "TextBox_6 " name= "TextBox_3 " type= "text " runat= "server "> <br>
商品XX名: <input id= "TextBox_a " name= "TextBox_1 " type= "text " runat= "server "> <br>
商品XX名: <input id= "TextBox_b " name= "TextBox_2 " type= "text " runat= "server "> <br>
商品XX名: <input id= "TextBox_c " name= "TextBox_3 " type= "text " runat= "server "> <br>
很多input......... <br>
<br>
<br>
<br>
产品价格: <input id= "je " name= "金额 " type= "text " runat= "server " style= "WIDTH: 49px "> 元 <input id= "商品1 " type= "button " value= "商品1 " onclick= "JSfunction( '1 ', 'b ', '6 ') ">
<input id= "商品2 " type= "button " value= "商品2 " onclick= "JSfunction( '4 ', '5 ', 'c ') ">
</form>
</body>
</HTML>
[解决办法]
JSfunction(a,b,c)
{
var num = parseInt(document.getElmentById( "金额 ").value);
if(!isNaN(num))
{
if(num <5||num> 200)
{
alert( "wrong ");
return false;
}
else
{
for(var i=0;i <arguments.length;i++)
{
var t = document.getElementById( "TextBox_ "+arguments[i]);
if(t)
{
t.value=num;
t.style.backgroundColor= "yellow ";
}
}
}
}
}

热点排行