0
我試圖在rails中的apple
元素上添加onclick事件。這是咖啡。使用coffeescript在導軌4中的元素上創建彈出式引導
apple.on 'click',() ->
$(this).popover('[data-content="This is the body of Popover"]');
我該如何轉換它才能工作?
我試圖在rails中的apple
元素上添加onclick事件。這是咖啡。使用coffeescript在導軌4中的元素上創建彈出式引導
apple.on 'click',() ->
$(this).popover('[data-content="This is the body of Popover"]');
我該如何轉換它才能工作?
我將HTML data attribute
與JS attribute
混合。所以正確的答案是這樣的。
$('#apple').on 'click',() ->
$(this).popover({content = "This is the body of Popover"};
您應該檢查網頁上的元素並檢查控制檯以查看是否有任何JS錯誤。我認爲你也應該適當地引用'蘋果'。例如:
$('#apple').on 'click',() ->
$(this).popover('[data-content="This is the body of Popover"]');
我想將此添加爲評論,但我沒有足夠的代表。讓我知道你是怎麼辦的。
不,蘋果應該保持這樣,因爲它是一個上面定義的變量。我找出了問題所在。我將HTML數據屬性與JS屬性混合在一起。最終應該是這樣的。 'apple.on'點擊',() - > $(this).popover({content:「這是Popover的主體」});' – Lory