我有这个 jquery 脚本。我想将函数的返回值stockArt()
用于 function prod_actname()
。看来我遗漏了一些东西或者我的实现是错误的。我怎么可能这样做?
另一种情况是当StockArt()
值更改时,活动名称也必须更新。
说 Stock Art 颜色是绿色。并且活动名称颜色也更新为绿色,无需从prod_actname()
功能中选择绿色。它会随着 StockArt 颜色的变化而自动变化。它们必须是相同的颜色。
jQuery( document ).ready(function($) {
$('#preview_design').css("background-color","black");
$('#stock_art').change(function() {
var retVal = stockArt();
$('#prod_actname').data("stockData", retVal);
});
$('#prod_actname').change(function() {
var stockData = $('#prod_actname').data("stockData");
prod_actname(stockData);
});
function stockArt()
{
var returnValue = null;
var selectStock_Art = $('#stock_art :selected').val();
if(selectStock_Art == '31145-RB-emb')
{ // green
$('#stockArt_img').removeClass().addClass('stock_art_grbg1');
}
else if(selectStock_Art == '33441-RB-emb1')
{ // yellow
$('#stockArt_img').removeClass().addClass('stock_art_yebg2');
}
else if(selectStock_Art == '33441-RB-emb2')
{ // gold
$('#stockArt_img').removeClass().addClass('stock_art_gobg3');
}
else {
$('#stockArt_img').removeClass();
}
returnValue = selectStock_Art;
return returnValue;
}
function prod_actname(stockData){
var StockArtResult = stockData;
//User stockData as needed
// assign the value to a variable, so you can test to see if it is working
var selectActivity_Name = $('#prod_actname :selected').val();
//alert(selectActivity_Name);
if(selectActivity_Name == 'Baseball')
{
$('#activityName_img').removeClass();
if(stockArtValue == '31145-RB-emb'){
$('#activityName_img').addClass('activity_name_GRbg1');
}
else if(stockArtValue == '33441-RB-emb1'){
$('#activityName_img').addClass('activity_name_YEbg1');
}else if(stockArtValue == '33441-RB-emb2') {
$('#activityName_img').addClass('activity_name_GObg1');
}
}
else if(selectActivity_Name == 'Basketball')
{
$('#activityName_img').removeClass();
if(stockArtValue == '31145-RB-emb'){
$('#activityName_img').addClass('activity_name_GRbg2');
}
else if(stockArtValue == '33441-RB-emb1'){
$('#activityName_img').addClass('activity_name_YEbg2');
}else if(stockArtValue == '33441-RB-emb2') {
$('#activityName_img').addClass('activity_name_GObg2');
}
}
else if(selectActivity_Name == 'Boys Basketball')
{
$('#activityName_img').removeClass();
if(stockArtValue == '31145-RB-emb'){
$('#activityName_img').addClass('activity_name_GRbg3');
}
else if(stockArtValue == '33441-RB-emb1'){
$('#activityName_img').addClass('activity_name_YEbg3');
}else if(stockArtValue == '33441-RB-emb2') {
$('#activityName_img').addClass('activity_name_GObg3');
}
}
else if(selectActivity_Name == 'Girls Basketball')
{
$('#activityName_img').removeClass();
if(selectStock_Art == '31145-RB-emb'){
$('#activityName_img').addClass('activity_name_GRbg4');
}
else if(selectStock_Art == '33441-RB-emb1'){
$('#activityName_img').addClass('activity_name_YEbg4');
}else if(selectStock_Art == '33441-RB-emb2') {
$('#activityName_img').addClass('activity_name_GObg4');
}
}
}
});