【发布时间】:2010-04-26 07:56:15
【问题描述】:
我之前找到了这个答案,如果按下按钮但未选中复选框,则会触发警报。
为什么这不起作用?
我有这个想法
<script src="http://code.jquery.com/jquery-latest.js"></script>
在正文中:
<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>
{literal}
<script type="text/javascript">
$(function() {
//checkbox
$("#checkbox2").click(function(){
//if this...
//alert("this")...
if($("#checkbox2").is(':checked'))
{
alert("im checked");
}
});
//button
$("#fullfor_btn").click(function(e){
if(!$("#checkbox2").is(':checked'))
{
alert("you did not check the agree to terms...");
e.preventDefault();
}
});
}
</script>
{/literal}
这在另一个 .tpl 上:
<label></label>
<button type="submit" class="submit" name="{$method}" id="fullfor_btn" title="Fullfør bestillingen nå" value=""> </button>
可能出了什么问题? jQuery 根本不会触发任何东西。
更新 id 项已更改为 checkbox2,仍然没有任何反应。
【问题讨论】: