如何从div中的字符串中删除特定关键字

时间:2015-04-16 10:52:22

标签: javascript c# jquery

<p>hello how are u</p><p>&nbsp;</p>
<div class="fbphotobox"><img id="img__kw_field_id" 
fbphotobox-src=" Uploads/Images/OriginalImages/developer_635647972105434266.jpg;" 
src="Uploads/Images/ResizedImages/developer_635647972105434266.jpg" alt="" /></div>

这是我的字符串,我需要从; .fbphotobox中删除src我正在尝试filter()但是我的代码中没有这个

var text = $("#<%=hdnDescription.ClientID%>").val();
var found = text.filter(".fbphotobox");

3 个答案:

答案 0 :(得分:1)

我建议你在服务器端修复它。

但是你可以使用,

&#13;
&#13;
$(document).ready(function() {
  //Read attribute and replace text
  $('#img__kw_field_id').attr('fbphotobox-src', function(){
	  return $(this).attr('fbphotobox-src').replace(";","");
  }); 
  
  alert($('#img__kw_field_id').attr('fbphotobox-src'));
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<img id="img__kw_field_id" fbphotobox-src=" Uploads/Images/OriginalImages/developer_635647972105434266.jpg;" src="Uploads/Images/ResizedImages/developer_635647972105434266.jpg" alt="" />
&#13;
&#13;
&#13;

答案 1 :(得分:-1)

尝试这样的事情:

var text = "hello; dafsdf sd sdf sdf sdf dsf!";
var result = text.replace(";", "");

答案 2 :(得分:-1)

尝试使用

var text = $("#<%=hdnDescription.ClientID%>").val();
var found = text.replace(";","");
希望它有所帮助。