带JS和Mobile的复选框

时间:2015-06-10 11:25:48

标签: javascript

您好,并提前感谢您的帮助 在我的商店页面中,当用户同意这些条款时,我会选中一个复选框。当他选中复选框时,提交按钮被禁用(false)。我的问题是这个解决方案不能在iPhone和其他移动设备上运行。

以下是代码:



function terms() {
  if (document.getElementById("cbTerms").checked)
    document.getElementById("submit").disabled = false;
  else
    document.getElementById("submit").disabled = true;
}

function cbc() {
  if (document.getElementById("cbc").checked)
    document.getElementById("cbc") = ("הריני מאשר קבלת מבצעים והטבות אל הדואר האלקטרוני מפראיה");
  else
    document.getElementById("cbc").value = ".";
}

<input class="btn btn-toranj alt" name="submit" type="submit" id="submit" value="לרכישה" disabled="true">
<br>
<br>
<input type="checkbox-0" id="cbTerms" name="cbTerms" onclick="terms();" style="width:15px; height:15px;">
<p style="margin-bottom:0px; font-size:14px; display: -webkit-inline-box;">הריני מאשר כי קראתי את <a href="regulations.html" style="color:#E49D1F;">התקנון</a>
</p>
<br>
<input type="checkbox" id="cbc" name="os3" oninput="cbc()" style="width:15px; height:15px;">
<p style="margin-bottom:0px; font-size:14px; display: -webkit-inline-box;">הריני מאשר קבלת מבצעים והטבות אל דואר האלקטרוני</p>
<input type="hidden" value="הטבות ומבצעים" id="on3" name="on3">
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:1)

乍一看,您的第一个复选框实际上不是复选框。

<input type="checkbox-0" ...&GT;应该更像是:<input type="checkbox" ...>

通过此更改,它将起作用。

P.S:

考虑为if() {} else {}语句使用大括号,因为如果您将来更改某些内容(例如添加一行代码)并忘记添加它们,您可能会遇到一些逻辑错误。

答案 1 :(得分:0)

更改事件优先于点击。此外,您还可以随时通过当前点击的复选框

 <input class="btn btn-toranj alt" name="submit" type="submit" id="submit" value="לרכישה" disabled="true">
 <br><br>
 <input type="checkbox" id="cbTerms" name="cbTerms"  onchange="terms(this);" style="...">
 <p style="...">הריני מאשר כי קראתי את 
 <a href="regulations.html" style="...">התקנון</a>
 </p>
 <br>      
 <input type="checkbox" id="cbc" name="os3"  onchange="cbc(this)" style="...">
 <p style="...">הריני מאשר קבלת מבצעים והטבות אל דואר האלקטרוני</p>
 <input type="hidden" value="הטבות ומבצעים" id="on3" name="on3">

 <script type="text/javascript">
 function terms(me)
 {
     document.getElementById("submit").disabled = !me.checked;
 }
  function cbc(me){
    var val=document.getElementById("cbc").checked?
        "הריני מאשר קבלת מבצעים והטבות אל הדואר האלקטרוני מפראיה":".";
    document.getElementById("cbc").value = val;
}
 </script>