1
我想知道是否有一種方法可以動態地使用jQuery添加rails image_tag。在jQuery中添加rails image_tag
$(targetPlayerElement).html("<%= image_tag 'User.find_by_id(27).profile_picture'%>");
這就是我到目前爲止所嘗試的。
謝謝你的幫助。
我想知道是否有一種方法可以動態地使用jQuery添加rails image_tag。在jQuery中添加rails image_tag
$(targetPlayerElement).html("<%= image_tag 'User.find_by_id(27).profile_picture'%>");
這就是我到目前爲止所嘗試的。
謝謝你的幫助。
你可以嘗試使用:
$(targetPlayerElement).html('<%= image_tag User.find_by_id(27).profile_picture %>');
那一定是這樣的:
$(targetPlayerElement).html('<img src="src" alt="46" />')
如果您在控制檯中得到一個Uncaught SyntaxError: missing) after argument list
錯誤,則是因爲image_tag
是雙引號裏面,而src
的image_tag
也將用雙引號括起來。
如果是字符串,則不需要引用User.find_by_id(27).profile_picture
的結果,將會被引用。
哪個版本的Rails?使用find
代替find_by_id
。
此外,使用單引號將image_tag
打印出來。
感謝您的幫助,它生成的HTML代碼正確,但即時通訊語法錯誤,我無法弄清楚。 Uncaught SyntaxError:missing)在參數列表後 – jrocc
由於雙引號內的雙引號,我更新了答案。 –
它的工作非常感謝你! – jrocc