简体   繁体   English

django中getElementById的使用方法

[英]How to use getElementById in django

I'm trying to generate a code for editing posts using modal that are made before but it shows "Identifier or string literal or numeric literal expected" and "Statement expected" ERROR here is my code:我正在尝试使用之前制作的模态生成用于编辑帖子的代码,但它显示“预期的标识符或字符串文字或数字文字”和“预期的声明”错误这是我的代码:

` `

function submitHandler(){
       const textareaValue = document.getElementById("textarea_"${post.id}).value
</script>

<button type="button" class="btn btn-secondary"onclick=submitHandler({{post.id}}) > Save Changes</button>

` `

want to submit change to editing posts.想要提交对编辑帖子的更改。

if your are sending the textarea id via onclick, so didn't need to get it again via jinja or django template.如果您通过 onclick 发送textarea id,那么不需要通过 jinja 或 django 模板再次获取它。

<script>
   function submitHandler(post_id){
   my_textarea = 'textarea_'.concat(post_id);  
   const textareaValue = document.getElementById(my_textarea).value
</script>

<button type="button" class="btn" onclick=submitHandler({{post.id}})> Save Changes</button>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM