iT邦幫忙

0

如何添加值到 jquery 的 data- ?

我想把值丟給 data- 系列

attr('data-discount_id', response.discount_id)

但我發現這樣沒辦法運行?
確定 response.discount_id 有值
有什麼方式可以帶值進去?

神Q超人 iT邦研究生 5 級 ‧ 2018-07-14 14:23:33 檢舉
有前面選擇器的樣子嗎?
火爆浪子 iT邦研究生 1 級 ‧ 2018-07-14 14:26:26 檢舉
$('#xxx').attr('data-discount_id', response.discount_id);
神Q超人 iT邦研究生 5 級 ‧ 2018-07-14 14:40:57 檢舉
我剛剛用簡單的程式碼試了一下,
感覺應該沒有問題:
https://codepen.io/ms314006/pen/bjVzYa
要不要試著先寫固定的值試試看,
例如:$('#xxx').attr('data-discount_id', 'strTest');
看會不會出錯,或是用F12確認一下$('#xxx')是否真的有抓到要的東西。
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

4
最佳解答

把你的html放上來吧,每次都要猜半天妳的問題~
/images/emoticon/emoticon05.gif

看更多先前的回應...收起先前的回應...
火爆浪子 iT邦研究生 1 級 ‧ 2018-07-14 14:46:06 檢舉

我發現可以了,XAMPP 竟然有CACHE。。。

神Q超人 iT邦研究生 5 級 ‧ 2018-07-14 14:46:20 檢舉

最佳解答XD

/images/emoticon/emoticon06.gif

柯柯 iT邦新手 3 級 ‧ 2018-07-18 11:35:19 檢舉

/images/emoticon/emoticon39.gif

我要發表回答

立即登入回答