Im using PRE tag of HTML and I need on click to clear the content of it, I've tried the following without success.
我使用的是HTML的预标记,我需要点击以清除它的内容,我尝试了以下方法,但没有成功。
$('#display').clear;
$('#display').val("");
In the index html I use it like this
在索引html中,我像这样使用它
<pre id="display"></pre>
6 个解决方案
#1
2
You used $('selector').val('')
and it is for input boxes, and won't work here!
您使用了$('selector').val("),它用于输入框,在这里行不通!
I suggest you to use one of the bellow ways:
我建议你用下面的方法:
$(document).ready(function(){
$("#delete-1").click(function(){
$('#display1').html('');
});
$("#delete-2").click(function(){
document.getElementById('display2').innerHTML ="";
});
$("#delete-3").click(function(){
$('#display3').empty();
});
$("#delete-4").click(function(){
$('#display4').text('');
});
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<pre id="display1">
Here is pre content
</pre>
<br/>
<pre id="display2">
Here is pre content
</pre>
<br/>
<pre id="display3">
Here is pre content
</pre>
<br/>
<pre id="display4">
Here is pre content
</pre>
<br/>
<a id="delete-1" href="#">Delete #1</a>
<a id="delete-2" href="#">Delete #2</a>
<a id="delete-3" href="#">Delete #3</a>
<a id="delete-4" href="#">Delete #4</a>
#2
4
Use html("")
to clear content
使用html(“”)清除内容
$('#display').html("");
#3
3
If you are using jquery then use:
如果您正在使用jquery,请使用:
<script>
$( "#display" ).empty();
</script>
Make sure you are loading jquery.
确保加载了jquery。
#4
1
Try using simple javascript
试着用简单的javascript
document.getElementById('display').innerHTML ="";
Hope this helps.
希望这个有帮助。
#5
1
this clear the data between the tag
这将清除标记之间的数据
$('#display').text('');
#6
1
$('#display').html("");
Here is the working fiddle example.
https://fiddle.jshell.net/75fLkhmz/
这是一个工作的小提琴例子。https://fiddle.jshell.net/75fLkhmz/
#1
2
You used $('selector').val('')
and it is for input boxes, and won't work here!
您使用了$('selector').val("),它用于输入框,在这里行不通!
I suggest you to use one of the bellow ways:
我建议你用下面的方法:
$(document).ready(function(){
$("#delete-1").click(function(){
$('#display1').html('');
});
$("#delete-2").click(function(){
document.getElementById('display2').innerHTML ="";
});
$("#delete-3").click(function(){
$('#display3').empty();
});
$("#delete-4").click(function(){
$('#display4').text('');
});
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<pre id="display1">
Here is pre content
</pre>
<br/>
<pre id="display2">
Here is pre content
</pre>
<br/>
<pre id="display3">
Here is pre content
</pre>
<br/>
<pre id="display4">
Here is pre content
</pre>
<br/>
<a id="delete-1" href="#">Delete #1</a>
<a id="delete-2" href="#">Delete #2</a>
<a id="delete-3" href="#">Delete #3</a>
<a id="delete-4" href="#">Delete #4</a>
#2
4
Use html("")
to clear content
使用html(“”)清除内容
$('#display').html("");
#3
3
If you are using jquery then use:
如果您正在使用jquery,请使用:
<script>
$( "#display" ).empty();
</script>
Make sure you are loading jquery.
确保加载了jquery。
#4
1
Try using simple javascript
试着用简单的javascript
document.getElementById('display').innerHTML ="";
Hope this helps.
希望这个有帮助。
#5
1
this clear the data between the tag
这将清除标记之间的数据
$('#display').text('');
#6
1
$('#display').html("");
Here is the working fiddle example.
https://fiddle.jshell.net/75fLkhmz/
这是一个工作的小提琴例子。https://fiddle.jshell.net/75fLkhmz/