我在包含HTML javascript的python程序的 init (自我)函数中声明了一个变量。我无法访问javascript中的变量。这是我写的代码。
def __init__(self,):
self.inc = 0
def resultstableupdate(self,list,type):
if (type == "img") and (result_status == 1):
self.htmlapp.write("<td><button id=\"myBtn"+str(self.inc)+"\"><b>view</b></button>"
"<div id=\"myModal\" class=\"modal\">"
"<div class=\"modal-content\">"
"<span class=\"close\">×</span>"
"<img src="+list[self.Comments]+" alt=\"check image path\" hspace=\"5\" width=\"100px\" height=\"100px\">"
"<img src="+list[self.ExpectedValue]+" alt=\"check image path\" hspace=\"10\" width=\"100px\" height=\"100px\"></td></div></div>"
"<script>"
"var modal = document.getElementById(\"myModal\");"
"var btn = document.getElementById(\"myBtn\".concat(+self.inc+));"
"var span = document.getElementsByClassName(\"close\")[0];"
"btn.onclick = function() {"
"modal.style.display = \"block\";}"
"span.onclick = function() {"
"modal.style.display = \"none\";}"
"window.onclick = function(event) {"
"if (event.target == modal) {"
"modal.style.display = \"none\";}}"
"</script>")
self.inc+=1
问题是我想在html中使用变量'inc'。我不想使用功能,只想在标签内传递按钮ID。
我对html-js并不陌生,任何帮助都很好
预期:每按一次按钮,都应显示图像
Acutal:仅出现按钮