var d = "";
var c = "";
var table = "<div id='h' style='overflow-y:scroll;overflow-x:hidden;height:60vh'>";
db.collection("Notes")
.where("user","==",current_email)
.get().then((snapshot)=>{
snapshot.docs.forEach(doc=>{
count++;
d = doc.data()["title"];
c = doc.data()["content"];
if(count != 0){
table += "<b><label id='titleb'>"+d.toUpperCase()+"</label></b><br><label id='titleba'>"+c+"</label><b><img id='del' src='del.svg' onclick='delme('"+d+"')'><br><br><br>";
}
else{
table += "<label>You dont have any notes</label>";
}
我试图在单击图像时将值传递给js函数,但由于输入的意外结束而出现错误。谁能告诉我如何将参数传递给此函数。我正在动态编写此HTML内容,并且需要传递值
function delme(dd){
console.log(dd);
}
在定义HTML属性时,请尝试在所有位置都使用双引号(“)而不是单引号(')。
使用onclick='delme(\""+d+"\")'
table="";
count=1;
d="da"
c=1
if(count != 0){
table += "<b><label id='titleb'>"+d.toUpperCase()+"</label></b><br><label id='titleba'>"+c+"</label><b><img id='del' src='del.svg' onclick='delme(\""+d+"\")'><br><br><br>";
}
else{
table += "<label>You dont have any notes</label>";
}
$("#test").html(table)
function delme(dd){
console.log(dd);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="test"></div>