我尝试选择img
并.sub rel='0'
触发点击,看起来像$('.sub[rel=0] img').trigger('click')
,但它不起作用。
这个选择器代码有什么问题$('.sub[rel=0] img')
谢谢!
<div class="sub" rel="0">
<img>
</div>
<div class="sub" rel="1">
<img>
</div>
更新
function geturlvars(){
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++){
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
};
realid = geturlvars()["id"]
function checkstate(){
if(realid){
$('.sub[rel=realid] img').trigger('click');
}
$('.sub[rel=realid] img').click(function(){
console.log('hi');
});
};
checkstate();