Javascript - 删除元素中的某些字符

时间:2017-01-01 18:17:50

标签: javascript html

如果我有一个值为“jklmnop'”的输入框,我该如何去除' k'使用javascript?

我正在思考以下几点:

<script th:inline="javascript">
/*<![CDATA[*/

    /*[# th:each="page : ${pages}"]*/
        ...
        var l = new google.maps.LatLng(/*[[${page.lat}]]*/, /*[[${page.long}]]*/);
        ...
    /*[/]*/

/*]]>*/
</script>

使用此javascript:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    recyclerView = (RecyclerView) findViewById(R.id.view);

    getOverflowMenu();

    android.support.v4.app.LoaderManager loaderManager = 
        getSupportLoaderManager();

    android.support.v4.content.Loader<Cursor> loader = 
        loaderManager.getLoader(loader_id);

    if (loader != null) 
        loaderManager.initLoader(loader_id, null, this);
    else 
        loaderManager.restartLoader(loader_id,null,this);

    recyclerView.setOnClickListener(new View.OnClickListener() {
         @Override
         public void onClick(View v) {
             Toast.makeText(getApplicationContext(),"touched",Toast.LENGTH_SHORT).show();;
         }
    });

    new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {
        @Override
        public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
            Toast.makeText(getApplicationContext(),"moved",Toast.LENGTH_SHORT).show();
            return true;
        }

        @Override
        public void onSwiped(RecyclerView.ViewHolder viewHolder, int swipeDir) {
            long id = (long) viewHolder.itemView.getTag();
            remove(id);
        }
    });
}

谁能告诉我为什么这不起作用?如果是这样,我需要做些什么才能使其发挥作用?

谢谢:)

1 个答案:

答案 0 :(得分:2)

您没有设置值。

var l = document.getElementById('letters');
l.value = l.value.replace('k','');