This question already has an answer here:
(这个问题在这里已有答案:)
I have a shopping cart that displays product options in a dropdown menu and if they select "yes", I want to make some other fields on the page visible.
(我有一个购物车,在下拉菜单中显示产品选项,如果他们选择“是”,我想让页面上的其他字段可见。)
The problem is that the shopping cart also includes the price modifier in the text, which can be different for each product.
(问题是购物车还包括文本中的价格修饰符,每个产品可能不同。)
The following code works: (以下代码有效:)
$(document).ready(function() {
$('select[id="Engraving"]').change(function() {
var str = $('select[id="Engraving"] option:selected').text();
if (str == "Yes (+ $6.95)") {
$('.engraving').show();
} else {
$('.engraving').hide();
}
});
});
However I would rather use something like this, which doesn't work:
(但是,我宁愿使用这样的东西,这是行不通的:)
$(document).ready(function() {
$('select[id="Engraving"]').change(function() {
var str = $('select[id="Engraving"] option:selected').text();
if (str *= "Yes") {
$('.engraving').show();
} else {
$('.engraving').hide();
}
});
});
I only want to perform the action if the selected option contains the word "Yes", and would ignore the price modifier.
(如果所选选项包含单词“是”,我只想执行操作,并忽略价格修饰符。)
ask by Jordan Garis translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…