【发布时间】:2010-04-26 16:54:28
【问题描述】:
如果用户在未选中此复选框的情况下尝试离开页面,我需要让它显示错误。它除了视觉之外没有其他用途,有没有办法实现这样的事情?
<span>
<input value="1" type="checkbox" name="salgsvilkar" ID="checkbox2" style="float:left;"
onclick="document.getElementById('scrollwrap').style.cssText='
border-color:#85c222;
background-color:#E5F7C7;';" />
<label for="checkbox2" class="akslabel">
Salgs og leveringsvilkår er lest og akseptert
</label>
</span>
附加的 CSS 仅用于样式,没有必要张贴。
我试过了:
{literal}
<script type="text/javascript">
if ($("#checkbox2").val()==1){
alert('Please accept the terms of sale');
//or you can use other method of showing the error. lightbox? showing error msg on a span, etc.
}
</script>
{/literal}
在复选框之前的标记中输入了这个,但它不想工作。
更新:
除了给出的答案,这里是表单提交代码..
{form action="controller=checkout action=payOffline query=id=$method" handle=$offlineForms[$method] method="POST"}
{include file="block/eav/fields.tpl" fieldList=$offlineVars[$method].specFieldList}
<div id="handel_fortsett_btns">
<p class="submit">
<a href="{link route=$return}" class="continueShopping" title="Fortsett å handle"><span><span><span><span> </span></span></span></span></a>
<input type="hidden" name="step" value="{$step}" />
<label></label>
<button type="submit" class="submit" name="{$method}" id="fullfor_btn" title="Fullfør bestillingen nå" value=""> </button>
</p>
</div>
{/form}
谢谢。
【问题讨论】:
标签: php javascript html checkbox smarty