jQuery& PHP - 动态选择的点击事件不起作用

时间:2013-05-12 18:48:03

标签: jquery javascript-events click

所以我有一些事情要发生:

1)使用数据库中的某个值设置变量。 ("褐色&#34)

2)我运行一个函数,找到与该haircolor相关的代码。 (" d&#34)

3)我模拟了一个带有该代码id的div的点击。

这是我的代码:

var dbHair = "<?=$myHair?>";
var dbEyes = "<?=$myEyes?>";

var eyeCode = hairEyesFind(dbHair);
var hairCode = hairEyesFind(dbEyes + "2");
var block = "#" + eyeCode + ".pickerOpt";

console.log(block); // LOG A
console.log($(block)); // LOG B

$(block).click();

Log A返回`&#34; #d.pickerOpt&#34;。

Log B返回[li#d.pickerOpt, prevObject: jQuery.fn.jQuery.init[1], context: document, selector: "#d.pickerOpt", jquery: "1.9.1", constructor: function…]

以下是我尝试执行.click()的HTML:

<div class="modelblock" style="width: 212px; height: 65px;">
    <ul id="hair" class="picker">
        <li id="z" class="pickerOpt"><span>.</span></li>
        <li id="b" class="pickerOpt"><span>.</span></li>
        <li id="c" class="pickerOpt"><span>.</span></li>
        <li id="d" class="pickerOpt"><span>.</span></li>
        <li id="e" class="pickerOpt"><span>.</span></li>
        <li id="f" class="pickerOpt"><span>.</span></li>
    </ul>
    <h3>Hair</h3>
</div>
<div class="modelblock" style="height: 65px; width: 142px;">
    <ul id="eye" class="picker">
        <li id="g" class="pickerOpt"><span>.</span></li>
        <li id="h" class="pickerOpt"><span>.</span></li>
        <li id="i" class="pickerOpt"><span>.</span></li>
        <li id="j" class="pickerOpt"><span>.</span></li>
    </ul>
    <h3>Eyes</h3>
</div>

0 个答案:

没有答案