我有一个包含货币值的下拉菜单,并且会加载一个新页面,并将所选货币作为 URL 中的值。其代码如下:
<div id="procurselect">
<a href="javascript:void(0)" id="chosedCur"><?php echo $curr ; ?></a>
<ul style="display: none;">
<li><a rel="nofollow" title="Euro" onclick="set_currency('http://www.example.com/product.php?pid=<?php echo " $pid " ;?>&cur=EUR');" href="javascript:void(0)" target="_top" rel=nofollow>EUR</a>
</li>
<li><a rel="nofollow" title="Pound Sterling" onclick="set_currency('http://www.example.com/product.php?pid=<?php echo " $pid " ;?>&cur=GBP');" href="javascript:void(0)" target="_top" rel=nofollow>GBP</a>
</li>
<li><a rel="nofollow" title="Canadian Dollar" onclick="set_currency('http:/www.example.com/product.php?pid=<?php echo " $pid " ;?>&cur=CAD');" href="javascript:void(0)" target="_top" rel=nofollow>CAD</a>
</li>
<li><a rel="nofollow" title="Australian Dollar" onclick="set_currency('http://www.example.com/product.php?pid=<?php echo " $pid " ;?>&cur=AUD');" href="javascript:void(0)" target="_top" rel=nofollow>AUD</a>
</li>
........(cont....)
</ul>
</div>
<script>
imitSelect.show({
Target: $('#procurselect'),
Width: 30
});
</script>
我的页面上有另一个使用 simplecart.js
添加产品按钮。
按钮代码如下:
<a class="item_add" href="javascript:;">
<img src="images/addtocart.png" alt="Add to Cart" width="197" height="58" />
</a>
我希望用户单击 addcart 按钮后禁用上述货币下拉列表,以便他无法再次从下拉列表中更改货币。
我正在使用 jQuery。
这在 jQuery 中怎么可能呢?
更新:
我需要禁用选项以保留在所有页面上....
提前致谢。
最佳答案
尝试以下操作:
HTML:
<a class="item_add" onclick="disableDropdown()">
<img src="images/addtocart.png" alt="Add to Cart" width="197" height="58">
</a>
JavaScript:
<script>
function disableDropdown(){
$("#procurselect").attr('disabled','disabled');
//or another option
$("#procurselect").css('pointer-events','none'); // this makes it unclickable
//or another option
$("#procurselect").prop( "disabled", true );
}
</script>
关于javascript - 如何在 jQuery 中单击按钮后禁用下拉菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24776145/