Jquery 删除<;nobr></nobr>;一串

Jquery 删除<;nobr></nobr>;一串,jquery,Jquery,我有一个包含以下字符串的变量。我想删除和,只保留里面的内容 alert(product_code); 产生 <nobr>209/00254/01</nobr> 尝试以下任一方法: $(this).text(); 或 如果要完全删除它们(从原始文件中),可以使用例如: $("nobr").replaceWith(function() { return $(this).contents() }); 。或者,结果(因为它们在结果中是空格): 如果代码真的是这样,您可以使

我有一个包含以下字符串的变量。我想删除
,只保留里面的内容

alert(product_code);
产生

<nobr>209/00254/01</nobr>
尝试以下任一方法:

$(this).text();


如果要完全删除它们(从原始文件中),可以使用例如:

$("nobr").replaceWith(function() { return $(this).contents() });
。或者,结果(因为它们在结果中是空格):


如果代码真的是这样,您可以使用纯javascript实现这一点:

product_code = '<nobr>209/00254/01</nobr>';

// using simple string manipulation
alert( product_code.substring( 6, product_code.length - 7 ) );

// using regular expressions
alert( product_code.match( '<nobr>(.*)</nobr>' )[1] );

// using a bit more powerful regular expression
result = product_code.match( '<nobr>((\\d+)/(\\d+)/(\\d+))</nobr>' );
alert( result[1] ); // 209/00254/01
alert( result[2] ); // 209
alert( result[3] ); // 00254
alert( result[4] ); // 01
product_code='209/00254/01';
//使用简单的字符串操作
警报(产品代码子字符串(6,产品代码长度-7));
//使用正则表达式
警报(产品代码匹配(“(.*”)[1]);
//使用更强大的正则表达式
结果=产品代码匹配(“(\\d+)/(\\d+)/(\\d+)/(\\d+)));
警报(结果[1]);//209/00254/01
警报(结果[2]);//209
警报(结果[3]);//00254
警报(结果[4]);//01

如果您有多个:

$(“nobr”,this).each(function(){

$(this.replaceWith(函数(){return$(this.contents()})


}))

我尝试了第一个,但这只是给我的文本,但后面有空格。将在第二个响应上尝试第二个answer.javscript错误。XML筛选器应用于非XML值({0:#1=({}),上下文:#1#,长度:1}),您可以始终使用第一个答案修剪字符串。忘记在第二个解决方案中添加对children方法的调用。@用户,您可以使用` char来包装内联代码。。就像往常一样,您可以使用精确的、简单的答案来完成!!!product_code=$.trim($(this.text());这正是我需要的。
$("nobr").replaceWith(function() { return $(this).contents() });
var product_code = $.trim($(this).text());
var product_code = $(this).text();
product_code = '<nobr>209/00254/01</nobr>';

// using simple string manipulation
alert( product_code.substring( 6, product_code.length - 7 ) );

// using regular expressions
alert( product_code.match( '<nobr>(.*)</nobr>' )[1] );

// using a bit more powerful regular expression
result = product_code.match( '<nobr>((\\d+)/(\\d+)/(\\d+))</nobr>' );
alert( result[1] ); // 209/00254/01
alert( result[2] ); // 209
alert( result[3] ); // 00254
alert( result[4] ); // 01