-2

如果下拉设置为“是”,任何人都可以帮我编写一些 JavaScript 来帮助我添加这两个字段吗?

示例:如果 txtoneside_slider = Yes,则将 txtoneside 值添加到总计中

如果 txttwoside_slider = Yes 然后将 txttwoside 值添加到总计中

小提琴示例:http: //jsfiddle.net/adder1999/rcU44/2/

<div id="onewindow">
   <label for="txtoneside" class="editor-label"><strong>1 Side</strong></label>
    <div align="right">
      <input type = "text" name = "txtoneside" id="txtoneside" value = "45" />
       <select name="txtoneside_slider" id="txtoneside_slider" data-role="slider" data-mini="true" />
         <option value="no">No</option>
         <option value="yes">Yes</option>
       </select> 
         </div>

<div id="onewindow">
   <label for="txtoneside" class="editor-label"><strong>2 Side</strong></label>
    <div align="right">
      <input type = "text" name = "txttwoside" id="txtoneside" value = "25" />
       <select name="txttwoside_slider" id="txttwoside_slider" data-role="slider" data-mini="true" />
         <option value="no">No</option>
         <option value="yes">Yes</option>
       </select> 
         </div>


<div id="grandtotal">
   <label for="txtgrandtotal" class="editor-label"><strong>JOB TOTAL</strong></label>
   <div align="right">
   <input type = "text" name = "txtgrandtotal" id="txtgrandtotal" value = "" />
   </div>
 </div>
4

2 回答 2

0

您可以使用onChange实现一个 jquery 函数,如果 this 的值为 yes,则将输入框的值存储到一个变量中,如果两者都是 yes,则使用它来满足您的任何需求。

于 2013-03-20T15:44:32.827 回答
0

试试这个:

<div id="onewindow">
   <label for="txtoneside" class="editor-label"><strong>1 Side</strong></label>
    <div align="right">
      <input type = "text" name = "txtoneside" id="txtoneside" value = "45" />
       <select name="txtoneside_slider" id="txtoneside_slider" data-role="slider" data-mini="true" onchange="javascript: if(this.value=='yes'){ document.getElementById('txtgrandtotal').value=document.getElementById('txtoneside').value;}"/>
         <option value="no">No</option>
         <option value="yes">Yes</option>
       </select> 
         </div>


<div id="onewindow">
   <label for="txtoneside" class="editor-label"><strong>2 Side</strong></label>
    <div align="right">
      <input type = "text" name = "txttwoside" id="txttwoside" value = "25" />
       <select name="txttwoside_slider" id="txttwoside_slider" data-role="slider" data-mini="true"  onchange="javascript: if(this.value=='yes'){ document.getElementById('txtgrandtotal').value= parseInt(document.getElementById('txtgrandtotal').value) + parseInt(document.getElementById('txttwoside').value);}" />
         <option value="no">No</option>
         <option value="yes">Yes</option>
       </select> 
         </div>

<div id="grandtotal">
   <label for="txtgrandtotal" class="editor-label"><strong>JOB TOTAL</strong></label>
   <div align="right">
   <input type = "text" name = "txtgrandtotal" id="txtgrandtotal" value = "" />
   </div>
 </div>

也许是你想要的;它适用于你的小提琴。

萨卢多斯。

于 2013-03-20T15:55:43.767 回答