Javascript Onclick和jQuery单击协同工作,但返回false不在jQuery中工作
Onclick和jQuery单击协同工作,但返回false不在jQuery中工作。我想在单击打开下一页之前验证字段。我的代码的问题是,在这种情况下,若文件是空白的,它会打开下一页。我在每个空的情况下都使用return false。所以,直到所有字段都没有填满。下一页不应打开 Html代码Javascript Onclick和jQuery单击协同工作,但返回false不在jQuery中工作,javascript,jquery,Javascript,Jquery,Onclick和jQuery单击协同工作,但返回false不在jQuery中工作。我想在单击打开下一页之前验证字段。我的代码的问题是,在这种情况下,若文件是空白的,它会打开下一页。我在每个空的情况下都使用return false。所以,直到所有字段都没有填满。下一页不应打开 Html代码 <button id="onepage-guest-register-button" type="button" class="button secondary" onclick="$('login:gu
<button id="onepage-guest-register-button" type="button" class="button secondary" onclick="$('login:guest').checked=true; checkout.setMethod();"><span><span><?php //echo $this->__('Checkout as Guest') ?></span></span></button>
不要将
onclick
属性与onclick
事件处理程序混合使用。这太傻了
在大多数情况下,最好选择后者
1) 删除onclick
属性
<button id="onepage-guest-register-button" type="button" class="button secondary"><span><span><?php echo $this->__('Continue') ?></span></span></button>
为什么在同一元素上既有内联绑定又有非内联绑定?还有
$('login:guest')。checked=true
无效。jQuery不直接公开dom属性。正确的格式是$('login:guest')。prop('checked',true)
你的意思是什么?button onclick=“$('login:guest')。checked=true;checkout.setMethod();”。不正确?是的,正如我所指出的,这在语法上是不正确的;未捕获的TypeError:$(…).prop不是HtmlButtoneElement上的函数。(opcheckoutlogin.js:53)在HTMLButtonElement.dispatch(jquery-1.10.2.min.js:5)在HTMLButtonElement.v.handle(jquery-1.10.2.min.js:5)你能再次检查我的问题吗。我编辑了我的问题(html中的按钮onclick方法)。
<button id="onepage-guest-register-button" type="button" class="button secondary"><span><span><?php echo $this->__('Continue') ?></span></span></button>
jQuery('#onepage-guest-register-button').click(function(e){
// no idea
var email = jQuery('#login-email').val();
jQuery('.validate-email').attr('value', email);
// get values
var login_name = jQuery('#login_name').val();
var login_phone = jQuery('#login_phone').val();
var login_email = jQuery('#login_email').val();
// flag if errors is found; assume no errors by default
var err = false;
// clear errors?
jQuery('.login_name').empty();
jQuery('.login_phone').empty();
jQuery('.login_email').empty();
// show errors if any
if (login_name == '') {
jQuery('.login_name').text('Please enter full name');
err = true;
}
if (login_phone == ''){
jQuery('.login_phone').text('Please enter Phone Number');
err = true;
}
if (login_email == ''){
jQuery('.login_email').text('Please enter Phone email');
err = true;
}
// do the appropriate action depending if there are errors or not
if (err) {
return false;
} else {
$('login:guest').prop('checked', true);
checkout.setMethod();
}
});