简体   繁体   中英

add html+text to input of type submit using javascript

I am using a smartsearchbox webpart, and I am adding the text value of its submit input using javascript, like this:

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

now I want to append to the value a search icon using fontawesome library, how can I achieve that with javascript?

您可以使用value属性将按钮文本设置为以下内容

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

You could do it using the unicode version of the icon. You would also need to add the "fa" class unless you have already applied the fontawesome font family via another style/class or method:

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

Solution based on Font-awesome, input type 'submit'

See this answer for potentially adding a custom class instead of using "fa" that would prevent your site font from being overridden for the button text https://stackoverflow.com/a/11703274/1435302

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM