我想创建一个能够接受任何变量或多个变量并对其进行处理的通用/可扩展类。我想学习如何检查存在哪个字段、传递的字段数并对其进行处理。'fruitstall' 类可以接受 0 个或多个水果变量。
HTML:
<div class="fruitstall(apple,orange)"></div>
脚本:
$('.fruitstall').click(function(event){
if (get first variable value and check if it is an apple) {
//Show apple image
} elseif (get the next variable value and check if it is an orange) {
//Show orange image
}
alert('Number of fruit chosen are ' + (count number of variable passed to class) + ' ; ' fruit(index0) + fruit(index1));
});
恕我举个水果摊的例子,我觉得用更生动的方式提问会很有趣。:)
非常感谢你。