Jump to content
php.lv forumi

Ar load ielādēts saturs nereaģē uz js


keiG
 Share

Recommended Posts

Tātad ar jquery load ielādēta php lapa, kurā iekšā ir dropdown ar name="category".

 

saitā ir jquery skripts $("select[name=category]").change{....} bet ielādētais saturs nereagē uz šo skriptu!

 

Kā šo varētu labot?

Edited by keiG
Link to comment
Share on other sites

Visu noteikti nevaru iemest, jo tas ir ļoti daudz, bet kādu daļu varbūt.

 

Daļa no index lapas jquery

$(".edit").click(function(){
$("#editcont").html('<br/><div style="text-align:center"><img src="icons/loader.gif"></div>');
 var editid = $(this).attr("id");
 $("#editid").attr("value",editid);
$('#editcont').load('edit.php?id='+editid+"&token=<?php echo $token?>"); // Te tiek ielādēta lapa ////////////////////////////////////////////////
 $("#bkg,#edit_menu").fadeIn(500);
});
$("select[name=categoryedit]").live(change,function(){
alert('Yes');
$("#subcategoryedit").html("");
var cid = $(this).attr("value");
var items = [<?php
$res = mysql_query("SELECT * from `subcategory`");
$row = mysql_fetch_array($res,MYSQL_ASSOC);
while($row = mysql_fetch_array($res,MYSQL_ASSOC)){echo "[".$row["id"].",'".$row["name"]."'],";
}
?>]
var i=1;
var string="";
var subc=0;
string+= 'Subcategory:<br/><select name="subcategoryedit" class="input"><option value=0 >...</option>';
while(i<=items.length){
if(items[i-1][0]==cid){
subc++;
var sel="";
string += "<option value='"+i+"'>"+items[i-1][1]+"</option>";
};
i++;
}
if(subc>0){$("#subcategoryedit").html(string+"</select><br/><br/>");}else{$("#subcategoryedit").html("");};
});

 

Fragments no ielādētās lapas:

<div id="subcategoryedit">
Sub category:<br/><select name="subcategoryedit" class="input">
<option value="0" >...</option>
<?php
$res2 = mysql_query("SELECT * from `subcategory` order by id ASC");
while($row2 = mysql_fetch_array($res2,MYSQL_ASSOC)){
if($re['subcategory']==$row2["subid"]){$sel = "selected";}else{$sel="";};
if($row2['id']==$re['category']){echo "<option value=".$row2["id"]." ".$sel." >".$row2["name"]."</option>";};
}
?>
</select>
</div>

Edited by keiG
Link to comment
Share on other sites

1)ja DOM objekti vēl nav ielādēti, tiem nevar piešķirt eventus, tāpēc izmantojam:

$(function(){
 //šeit viss, kam notikt pēc lapas DOM ielādes
});

2)Eventu deleģēšanai nezimantojam live, bet on uz parent elementu:

$('.parent').on('click','.child',function(){
});

kur .parent iepriekš ielādēt DOM elemnents, bet .child var būt brīvi izveidoti DOM elementi jebkurā laikā

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...