Remove blankspace from td class with greasemonkey

荒凉一梦 提交于 2019-12-11 19:54:23

问题


If I have webpage with for example alot of <td class="house">111 22</td>. The numbers are random but classname is the same and the blankspace between the numbers are at same position in all of them, and I want to remove the space in all of them after page is loaded. How should the script look like to work?


回答1:


How about using this

var str = "111 22";    
    str = str.replace(" ","");

code example :

<script type="text/javascript">
 //Page Initial
 $(function() {
     removeSpace();
 });
 function removeSpace(){
   var str = $(".house").html();
       str = str.replace(" ","");
       $(".house").html(str);
 }

</script>



回答2:


Do this:

var elems = document.querySelectorAll('td.house');
for(var i = 0 ; i < elems.length; i++){
    elems[i].textContent = elems[i].textContent.replace(" ","");
}



回答3:


    use the following code:

   <script type="text/javascript">

    window.onload = removeSpace;

    function removeSpace() {
        var emt = document.getElementById("mytable");//mytable is the Id of the table
        d = emt.getElementsByTagName("tr")[0],
         r = d.getElementsByTagName("td");
        for (var i = 0; i < r.length; i++) {
            var str = r[i].innerText;
            r[i].innerText = str.replace(" ", "");
        }
    }

</script>


来源:https://stackoverflow.com/questions/22929488/remove-blankspace-from-td-class-with-greasemonkey

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!