单击按钮时替换图像

时间:2017-03-03 11:26:07

标签: javascript jquery html ajax

我试图在点击按钮时替换图像,但我似乎无法弄明白。我从我的ajax值中获取了一个来自我的服务器的图像test_df = test_df.sort_values('Passed?', ascending=False) .groupby(level=[0,1]) .first() print (test_df) Passed? foo a True b False qux a False b Ok 。我现在不想用当前通过ajax从服务器获取的照片替换当前照片。

index = [np.array(['foo', 'foo', 'foo', 'foo', 'qux', 'qux', 'qux']), np.array(['a', 'a', 'b', 'b', 'a', 'b', 'b'])]
data = np.array(['False', 'True', 'False', 'False', 'False', 'Acceptable', 'False'])
columns = ["Passed?"]
test_df = pd.DataFrame(data, index=index, columns=columns)
#print (test_df)

cat = ['False', 'Acceptable','True']
test_df["Passed?"] = test_df["Passed?"].astype('category', categories=cat, ordered=True)
print (test_df["Passed?"])
foo  a         False
     a          True
     b         False
     b         False
qux  a         False
     b    Acceptable
     b         False
Name: Passed?, dtype: category
Categories (3, object): [False < Acceptable < True]

test_df = test_df.sort_values('Passed?', ascending=False).groupby(level=[0,1]).first()
print (test_df)
          Passed?
foo a        True
    b       False
qux a       False
    b  Acceptable

1 个答案:

答案 0 :(得分:2)

你应该改变:

$(".search-result:first").clone().appendTo(".search").find("src").replace(photo);

为:

$(".search-result:first").clone().appendTo(".search").attr("src",photo);

如果您需要显示完整路径,可以使用以下选项:

//window.location.host //you'll get sub.domain.com:8080 or sub.domain.com:80
//window.location.hostname ////you'll get sub.domain.com
//window.location.protocol : you'll get http:
//window.location.port //you'll get 8080 or 80
//window.location.pathname //you'll get /virtualPath

var mainUrl =  window.location.protocol+"//"+window.location.hostname;

$(".search-result:first").clone().appendTo(".search").attr("src",mainUrl+"/img/"+photo);

这会给你http://example.com/img/photo/1583testImg.png