Uncaught SyntaxError:函数中的输入意外结束

时间:2019-03-08 21:00:20

标签: javascript jinja2

任何帮助将不胜感激。

 <button type="button" 
       id="myBtn" class="btn btn-primary"
       data-toggle="modal" data-target="#myModal"
       onclick="notify({"IP": "0.0.0.0-255.255.255.255", "app_code": "", "custodian_email": "", "custodian_id": "", "custodian_name": ""})">
     <i class="fab fa-telegram-plane" style="margin-right:5px"></i>
        Notify
    </button>

2 个答案:

答案 0 :(得分:3)

您正在使用双引号分隔onclick属性值,并分隔属性内部的字符串。无法解析,因为IP前的双引号结束了该属性。改为使用单引号。

<button type="button" 
   id="myBtn" class="btn btn-primary"
   data-toggle="modal" data-target="#myModal"
   onclick='notify({"IP": "0.0.0.0-255.255.255.255", "app_code": "", "custodian_email": "", "custodian_id": "", "custodian_name": ""})'>
 <i class="fab fa-telegram-plane" style="margin-right:5px"></i>
    Notify
</button>

答案 1 :(得分:0)

您正在内部字典和函数中使用“作为关闭和打开标签,只需更改

notify({"IP": "0.0.0.0-255.255.255.255", "app_code": "", "custodian_email": "", "custodian_id": "", "custodian_name": ""}

至: notify({'IP': '0.0.0.0-255.255.255.255', 'app_code': '...'})