昨天,我在 stackexchange 上问了一个问题,Sean 和 A. Wolff 已经对我的问题给出了令人满意的答案。 The link is here问题是下拉菜单的顶部有一个覆盖层,这使得它在有变化时不可见。我们删除了该覆盖层并且它起作用了。
我今天继续做我的元素,我意识到我提出的问题和答案并不完全是我想要的。我想要的是,我真的想要准确的用户点击。这意味着,在实现目标的过程中,我们不应从页面中删除任何类或元素。
这是一个极简代码。有一个下拉菜单,如果您在菜单中选择“Bedrag”,下拉菜单旁边会打开一个文本框。谁能帮助我如何使用 JQuery 或 JS 选择“Bedrag”?请注意,不应删除任何元素或类或任何内容。它应该只选择下拉列表中的元素并触发信号。我为此做了很多尝试,但归根结底,如果没有你们的帮助,我无法做到这一点。
这是代码:http://jsfiddle.net/so0h96ns/1/
下拉菜单的代码是:
<div data-custom-select class="select-price ">
<label for="price" data-label-hide class="has-hidden-label">Selecteer prijs</label>
<select name="adv.bedragplaats" id="price" class="price-field" data-price data-set-as-required >
<option value="">Kies...</option>
<option value="<amount>" >Bedrag</option>
<option value="gratis" >Gratis</option>
<option value="ruilen" >Ruilen</option>
<option value="teab" >Prijs overeen te komen</option>
<option value="nvt" >Niet van toepassing</option>
</select>
</div>
最佳答案
三个部分
//first assign the change event which opens the box on the side
$('.price-field').on("change", function () {
if ($(this).val() === "<amount>") {
console.log("the amount option has been selected now open THE BOX");
}
})
//then select the bedrang
.find('option[value="<amount>"]')
//then trigger the change event to open the box
.attr("selected", true).trigger("change");
这是 fiddle http://jsfiddle.net/orchid1/vtrsgLnr/1/
关于javascript - 使用 JavaScript 或 JQuery 模拟用户点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27346483/