开发者

Getting to grips with JQuery

I want to do "something like this" when a document loads:

$(':input:visible').each(function(i){
                                  
    if($(this.getAttribute('required')!=null)) { $(this).css({ 'border-color':'#800000' }); }                               
                                  
});

So in simple terms I have:

$(document).ready(function() {
    $(':input:visible').each(function(i){
    if($(this.getAttribute开发者_运维问答('required')!=null))
    { $(this).css({ 'border-color':'#800000' }); }  
    });
    });

Is there any reason why it doesn't work?


This line

if($(this.getAttribute('required')!=null)) {

Is very peculiar.

You want to use the attr function:

if ($(this).attr('required') != null) {

or, even better and more simply, an object property:

if (this.required) {


Use this code it works correctly

$(document).ready(function() {
    $('input:visible').each(function(i){
        if($(this).attr('required') != undefined)
            $(this).css({ 'border-color':'#800000' });  
    });
});


try this:

style:

input.requiredcss { 'border-color':'#800000'; }

JS:

$('#adminwrapinner').load('inc/frm_create.php', function(response, status, xhr) {

   var adminwrapinner = this;

   if (status == "success") {

     $(':input:visible:not(.requiredcss)', adminwrapinner).each(function(i){

        if($(this).attr('required')) { 
           $(this).addClass("requiredcss"); 
        } 

     });
   }   
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜