Javascript“if and else”语句

时间:2013-03-09 20:19:35

标签: javascript jquery html css

我有一个Terms of Service页面,我希望强制用户在单击“接受”按钮之前检查Checkbox。否则它应该显示一条弹出消息说

请在继续之前阅读ToS

如果已经选中并点击接受按钮,他们将重定向到官方网站。

任何人都可以帮助我吗?

2 个答案:

答案 0 :(得分:2)

试试这个:

<SCRIPT>

//Accept terms & conditions script (by InsightEye www.insighteye.com)
//Visit JavaScript Kit (http://javascriptkit.com) for this script & more.

function checkCheckBox(f) {
  if (f.agree.checked == false ) {
    alert('Please check the box to continue.');
    return false;
  } else {
    return true;
  }
}
</SCRIPT>

<form action="/yourscript.cgi-or-your-page.html" method="GET"
 onsubmit="return checkCheckBox(this)">

  <!--Enter your form contents here-->
  <b>By submitting, I agree that all info entered was done
     accurately & truthfully.</b><br>
     I accept: <input type="checkbox" value="0" name="agree">
  <input type="submit" value="Submit form">
  <input type="button" value="Exit" onclick="document.location.href='/index.html';">
</form>

或者这个:

<form name="frm">
  <input type="checkbox" name="chk" onClick="apply()">If you click this the specified
   url will open.
  <div align=center>&copy<a href="http://www.mine.com" style="color:#3D366F;text-decoration:none;cursor:pointer;font-size=13px">hscripts.com</a></div>
</form>
<script type="text/javascript">
  function apply() {
   if(document.frm.chk.checked==true) {
     window.open("http://www.mine.com/license/license.html");
   }
  }
</script>

答案 1 :(得分:0)

condition中查看submit handler

if (formname.checkboxname.checked == true)
   {
      //showalert

      return false;
   }else{

     //open your page
  }