jQuery 切换删除输入类型复选框

标签 jquery html css checkbox

我有一个复选框。它将更新作为输入文本框的 $('#express') 的值。如果我使用 .toggle 而不是 .click,复选框将被隐藏。

切换是我的复选框被删除或不可见的原因吗?

HTML

<form id="addupload" method="post" action="order_history/lightbox/mini-upload-form/upload.php" enctype="multipart/form-data">
     <div id="upload">
      <div id="drop">
      Drop Here
     <a>Browse</a>
    <input id="uplo" type="file" name="upl"  />
          </div>
     <ul> </ul>
     </div>
  <div id="formcontent">
        <label class="required" for="unitprice" title="Unit price"><input type="text" id="unitprice" name="unitprice" />Unit price</label>
    <label class="required" for="qty" title="How many pcs"><input type="text" id="qty" name="qty" />Quanity</label>
    <label class="required" for="express" title="Express within China"><input type="text" id="express"  name="express" />Express</label>
    <label class="required" for="linkURL" title="Insert a full URL http:\\"><input type="text" id="linkURL" name="linkURL" />Link</label>
        <label  for="yourdesc"   title="Describe your need clearly">Description<textarea id="yourdesc" name="yourdesc"></textarea></label>
            <label for="shunfeng" title="SF is RMB25 for 1kg ">Express ?<input type="checkbox" id="shunfeng" class="shunfeng" name="shunfeng" /></label>
            <label for="formsubmit" class="nocontent" id="uptest"><input  type="button"  id="submitButton" href="#" class="progress-button" onClick="upload()" value="Add to order" /><strong>Note:</strong> Items marked <img src="order_history/images/required.jpg" alt="Required marker" width="20" height="20" /> are required fields</label>
    </div>
 </form>

JQUERY

$("#shunfeng").toggle(
function(){ 
 $('#express').val("25");
 }, function(){
     $('#express').val("0");
     }
 );

CSS

.shunfeng{
width:15px;
height:15px;}

最佳答案

您正在使用的函数 $.toggle(fn, fn);jQuery 1.8 中已弃用并在 jQuery 1.9 中删除/p>

而且我认为你需要change事件

$("#shunfeng").change(function () {
    if(this.checked) {
        $('#express').val("25"); //If checked set value to 25
    } else {
        $('#express').val("0"); //If unchecked set value to 0
    }
});

关于jQuery 切换删除输入类型复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23263383/

相关文章:

css - -webkit-animation-play-state 在 Chrome 中不工作

html - 用于响应式排版的媒体查询

javascript - 将 parsefloat 字符串与 oncalculate 输入相乘时返回 NaN

不同语言的 jQuery .load()

html - 同一行的回声结果?

javascript - 如何使用 javascript 获取 html 表格单元格的内容 javascript 根据复选框

javascript - 正则表达式 - 用一个替换多个 html 标签

javascript - 在 Chrome 中激活窗口选项卡

javascript - 在CSS/JavaScript中,这个图标/字体插件是如何实现的?

html - 我的 CSS 代码有什么问题?