本文介绍了使用JQuery去除html标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 大家好, 所以我使用JQuery在SharePoint讨论列表中创建一个按钮,然后将我带到一个创建新的项目表单,然后在此表单有JQuery从讨论列表中提取我想要的内容并将其放在RTE文本区域中,并且工作正常,除了它带来所有的html标签,例如。 等.. 以下是我的代码,我需要了解如何删除这些标签并保持格式化。 function GetParam(name) { name = name.replace(/ [\ [] /, \\\\ \\ [)。replace(/ [\]] /, \\\ ]); var regexS = [\\\ \\?&] + name + =([^] *); var regex = new RegExp (正则表达式); var results = regex.exec( unescape ( window 。 location .href)); if (results == null ) 返回 ; else return 结果[ 1 ]; } $( document )。ready( function (){ // SP2010AddNewify(客户,/国际/列表/ mE%20Clients / NewForm.aspx,mE客户端); ExecuteOrDelayUntilScriptLoaded(GetBlogBody, sp.js); }); // //////////////// ////////////////////////////////////////////////// ////// // ////////// /////////////////////获取项目/////////////////////////// ///// function GetBlogBody(){ var id = GetParam( blogid); var clientContext = SP.ClientContext.get_current(); var oList = clientContext.get_web()。get_lists()。getByTitle(' 团队讨论'); var camlQuery = new SP.CamlQuery(); camlQuery.set_viewXml( < view>< query>< where>< eq>< ; fieldref name = ID />< value type =计数器 > + id + < / value>< / eq>< / where>< / query>< / view>); // camlQuery.set_viewXml(< view>< query>< where>< eq> ;< fieldref name =Title/>< value type =Text>普通话价格< / value>< / eq>< / where>< / query>< / view>) ; this .collListItem = oList.getItems(camlQuery); clientContext.load(collListItem); clientContext.executeQueryAsync(Function.createDelegate( this , this .onQuerySucceeded),Function.createDelegate ( this , this .onQueryFailed)); } function onQuerySucceeded(sender,args){ // alert('Query Success'); var listItemInfo = ' '; var listItemEnumerator = collListItem.getEnumerator(); var contentbody = ; while (listItemEnumerator.moveNext()){ var oListItem = listItemEnumerator.get_current(); contentbody = oListItem.get_item(' Body'); } // 结束时 CopyBodyToDescription(contentbody); // alert(CopyBodyToDescription); } // 结束功能 function CopyBodyToDescription(contentbody){ var systemDescriptionRTETextArea = $ ( textarea [Title ='Description']); // alert($(systemDescriptionRTETextArea).html()); $(systemDescriptionRTETextArea)的.html(contentbody); // alert($(systemDescriptionRTETextArea).html()); } // 结束功能 function onQueryFailed(sender,args){ alert(' 请求失败。' + args.get_message()+ ' \ n' + args.get_stackTrace()); } // /////////////// /////////////////////////////////////////////// // /////////////////// ////////////////////////////////////////// < / script> 解决方案 ( document )。ready( function (){ // SP2010AddNewify(Customer,/ International / Lists / mE%20Clients / NewForm.aspx,mE Clients) ; ExecuteOrDelayUntilScriptLoaded(GetBlogBody, sp.js); }); // //////////////// ////////////////////////////////////////////////// ////// // ////////// /////////////////////获取项目/////////////////////////// ///// function GetBlogBody(){ var id = GetParam( blogid); var clientContext = SP.ClientContext.get_current(); var oList = clientContext.get_web()。get_lists()。getByTitle(' 团队讨论'); var camlQuery = new SP.CamlQuery(); camlQuery.set_viewXml( < view>< query>< where>< eq>< ; fieldref name = ID />< value type =计数器 > + id + < / value>< / eq>< / where>< / query>< / view>); // camlQuery.set_viewXml(< view>< query>< where>< eq> ;< fieldref name =Title/>< value type =Text>普通话价格< / value>< / eq>< / where>< / query>< / view>) ; this .collListItem = oList.getItems(camlQuery); clientContext.load(collListItem); clientContext.executeQueryAsync(Function.createDelegate( this , this .onQuerySucceeded),Function.createDelegate ( this , this .onQueryFailed)); } function onQuerySucceeded(sender,args){ // alert('Query Success'); var listItemInfo = ' '; var listItemEnumerator = collListItem.getEnumerator(); var contentbody = ; while (listItemEnumerator.moveNext()){ var oListItem = listItemEnumerator.get_current(); contentbody = oListItem.get_item(' Body'); } // 结束时 CopyBodyToDescription(contentbody); // alert(CopyBodyToDescription); } // 结束功能 function CopyBodyToDescription(contentbody){ var systemDescriptionRTETextArea = ( textarea [Title ='Description']) ; // alert( (systemDescriptionRTETextArea).html() ); Hi All,So I am using JQuery to create a button in a SharePoint Discussion List that then takes me to a create new project form and then on this form have JQuery pulling the content I want from the Discussion List and dropping it in the RTE text area and that works fine except it brings ALL the html tags with it eg. ect..Here is my code below, I need to find out how to remove these tags and keep the formatting.function GetParam(name) {name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");var regexS = "[\\?&]"+name+"=([^]*)";var regex = new RegExp( regexS );var results = regex.exec( unescape(window.location.href) );if( results == null )return "";elsereturn results[1]; }$(document).ready(function() {//SP2010AddNewify("Customer","/International/Lists/mE%20Clients/NewForm.aspx", "mE Clients");ExecuteOrDelayUntilScriptLoaded(GetBlogBody, "sp.js");});///////////////////////////////////////////////////////////////////////////////////////////////////////////GET ITEM////////////////////////////////function GetBlogBody() { var id = GetParam("blogid"); var clientContext = SP.ClientContext.get_current(); var oList = clientContext.get_web().get_lists().getByTitle('Team Discussion'); var camlQuery = new SP.CamlQuery(); camlQuery.set_viewXml("<view><query><where><eq><fieldref name="ID" /><value type="Counter">" + id + "</value></eq></where></query></view>"); //camlQuery.set_viewXml("<view><query><where><eq><fieldref name="Title" /><value type="Text">Mandarin prices</value></eq></where></query></view>"); this.collListItem = oList.getItems(camlQuery); clientContext.load(collListItem); clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));}function onQuerySucceeded(sender, args) {//alert('Query Success'); var listItemInfo = ''; var listItemEnumerator = collListItem.getEnumerator(); var contentbody = ""; while (listItemEnumerator.moveNext()) { var oListItem = listItemEnumerator.get_current(); contentbody = oListItem.get_item('Body');}// end while CopyBodyToDescription(contentbody); //alert(CopyBodyToDescription);} // End Functionfunction CopyBodyToDescription(contentbody) {var systemDescriptionRTETextArea = $("textarea[Title='Description']");//alert($(systemDescriptionRTETextArea).html());$(systemDescriptionRTETextArea).html(contentbody);//alert($(systemDescriptionRTETextArea).html());}// End Functionfunction onQueryFailed(sender, args) { alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());}///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////</script> 解决方案 (document).ready(function() {//SP2010AddNewify("Customer","/International/Lists/mE%20Clients/NewForm.aspx", "mE Clients");ExecuteOrDelayUntilScriptLoaded(GetBlogBody, "sp.js");});///////////////////////////////////////////////////////////////////////////////////////////////////////////GET ITEM////////////////////////////////function GetBlogBody() { var id = GetParam("blogid"); var clientContext = SP.ClientContext.get_current(); var oList = clientContext.get_web().get_lists().getByTitle('Team Discussion'); var camlQuery = new SP.CamlQuery(); camlQuery.set_viewXml("<view><query><where><eq><fieldref name="ID" /><value type="Counter">" + id + "</value></eq></where></query></view>"); //camlQuery.set_viewXml("<view><query><where><eq><fieldref name="Title" /><value type="Text">Mandarin prices</value></eq></where></query></view>"); this.collListItem = oList.getItems(camlQuery); clientContext.load(collListItem); clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));}function onQuerySucceeded(sender, args) {//alert('Query Success'); var listItemInfo = ''; var listItemEnumerator = collListItem.getEnumerator(); var contentbody = ""; while (listItemEnumerator.moveNext()) { var oListItem = listItemEnumerator.get_current(); contentbody = oListItem.get_item('Body');}// end while CopyBodyToDescription(contentbody); //alert(CopyBodyToDescription);} // End Functionfunction CopyBodyToDescription(contentbody) {var systemDescriptionRTETextArea =("textarea[Title='Description']");//alert((systemDescriptionRTETextArea).html()); 这篇关于使用JQuery去除html标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-06 07:36