使用 javascript 添加 html+文本到提交类型的输入

add html+text to input of type submit using javascript

我正在使用 smartsearchbox webpart,我正在使用 javascript 添加其提交输入的文本值,如下所示:

$("#p_lt_ctl02_pageplaceholder_p_lt_ctl03_SmartSearchBox1_btnSearch").val('{%GetResourceString("search")%}');

现在我想使用 fontawesome 库将搜索图标附加到该值,如何使用 javascript 实现?

您可以使用值属性来设置按钮文字如下

$("#p_lt_ctl02_pageplaceholder_p_lt_ctl03_SmartSearchBox1_btnSearch").value = '{%GetResourceString("search")%}';

您可以使用图标的 unicode 版本来完成。您还需要添加 "fa" class 除非您已经通过另一个 style/class 或方法应用了 fontawesome 字体系列:

$("#p_lt_ctl02_pageplaceholder_p_lt_ctl03_SmartSearchBox1_btnSearch").addClass("fa").val("\uf002 {%GetResourceString("search")%}");

解决方案基于Font-awesome, input type 'submit'

查看此答案可能会添加自定义 class 而不是使用 "fa" 以防止您的站点字体被按钮文本

覆盖