点击按钮改变input text的value值

来源:互联网 发布:淘宝连衣裙店铺推荐 编辑:程序博客网 时间:2024/05/01 12:12
js代码:
<scripttype="text/javascript">
var textValue=1;
window.onload = function()
{
   varhtml=document.body.innerHTML;
   document.body.innerHTML=html.replace(/value="?javascript:(\w+)"?/ig,
                  function(s,s1){return 'value="'+window[s1] +'"'});
   
   
   $("#add").click(function(){
    
    document.getElementByIdx_x_x_x("amount").value=++textValue;
    
    });
   $("#lose").click(function(){
    if(document.getElementByIdx_x_x("amount").value>1)
    document.getElementByIdx_x_x("amount").value=--textValue;
    });   
</script>
 
 
html代码:
<div
     style="height:30px; width: 100%; border-top: 1px solid #E0E4E0; border-bottom:2px solid #E0E4E0">
     <tablestyle="width: 100%">
      <tr>
       <td>数量:
        <button id="lose"
         style="width:25px; height: 25px; background-color:#F79D2D">-</button>
        <inputid="amount"type="text" value="javascript:textValue" style="width:30px; color: red" />
        <button id="add"
         style="width:25px; height: 25px; background-color:#F79D2D">+</button>
       </td>
       <tdstyle="padding-right: 5px; width: 30%;">
        <div>
         <spanstyle="float: right; color:red"><strong>¥</strong>:66666</span>
        </div>
       </td>
      </tr>
     </table>
    </div>
 
效果
点击按钮改变input <wbr>text的value值

 

 
加个初始化函数,在文档下载完成后,把html代码中的js变量标志替换成js变量的值
 
0 0
原创粉丝点击