ajax ,html and javascript
ajax ,html and javascript
如何替换两条消息(好的和坏的)?假设字段中的数据是否正确显示良好,如果不是 - 显示不好,但比我再次更改它,因此消息将相应更改。
(我对这一切很陌生)
$(document).ready(function () {
$('#button').click(function(e){
var result = true,
ok = '<p>good</p>',
failed = '<p>bad</p>',
err;
$('input').each(function(index,obj){
var obj = $(obj);
if (obj.attr('id') == 'button'){
return false;
}
err = validateInput(o);
markInput(o,err);
if (!err){
result = false;
}
});
if (result){
$('#myForm').after(good);
$.ajax();
}
else{
$('#myForm').after(bad);
$.ajax();
}
});
而不是使用 .after
有一个元素作为消息的占位符并更新其 html:
<form>
<!-- all your code -->
<p id="message"></p>
</form>
// JavaScript
$("#myForm #message").html(good);
// also just `$("#message")` will work, and you can probably leave
// the `<p>` parts off of `good` and `bad`
更改:
if (result){
$('#myForm').after(good);
$.ajax();
}
else{
$('#myForm').after(bad);
$.ajax();
}
自:
if (result){
$('#myForm').after(ok);
$.ajax();
}
else{
$('#myForm').after(failed);
$.ajax();
}
你没有使用你创建的变量,名为"ok"和"failed",而是在不存在的.after()中输入了"好"和"坏"。还可以考虑使用 $('#messagePlaceHolder').replace(ok or failed) 而不是 .after,其中 messagePlaceHolder 是一个 .
相关文章:
- JavaScript and LiveView (TIBCO Live Datamart)
- Javascript and onMouseOver
- javascript and css firefox issue
- geolocation with javascript and ruby on rails
- Javascript and the DOM issues
- Javascript and Java Communication
- Javascript and Knockout
- Javascript and Css: Height does not change
- javascript and Internet Explorer 8
- Javascript and html, UI construction
- Javascript and Lightbox
- javascript and css styling
- JavaScript and URL parameters
- Javascript and singleton pattern
- Javascript and Ajax Calls
- OAuth, javascript and many URI's
- Javascript and AJAX post method
- javascript and web services WSDL
- javascript and webview in android
- Javascript & and | symbols