jquery .trigger() doesn't seem to work
This is my code :
$(document).ready(function () {
//alert("wa");
$("#wis").trigger('click');
$("#wis,#wib").click(function (){
alert("clciked");
if(!$(this).hasClass("dealsb")) {
$(".dealb").removeClass("dealsb");
$(this).addClass("dealsb");
var id=$(this).attr("id");
$.post("deals.php",{'r开发者_开发知识库eq':id},function(data){
//alert("works");
$("#deals").html(data);});
}
});
});
</script>
<div id='wib' class='dealb'>What I've Purchased</div><div id='wis' class='dealb'>What I've Sold</div>
<div id="deals" style='position:absolute;left:0px;top:100px;width:600px;height:300px'></div>
Here $("#wis").trigger('click');
doesn't seem to work. When I click #wis
or #wib
though, the alert gets fired off and everything runs perfectly.
You're triggering it before you add the click handler, so the behavior you're seeing makes perfect sense. Move the trigger
to the end of your <script>
tag and you should be set.
精彩评论